scorpionnishme
BAN USERYour algorithm seems to be incorrect.
Consider the case,
List1: 1, 4, 6, 10, 11
List2: 2, 3, 20, 40, 60
And you need to find the top 2 elements. Using your algorithm we compare 4 and 3 and end up picking 2, 3 from List 2 as the answer.
Oh I think I misread the question, I thought the words needed to be a substring.
If the sub words do not need to be of consecutive characters, the recursion will look something like this:
Either a character will be a part of the solution or not.
str = original string
index = current string index
currWord: current set of alphabets which are a contender for a word
getSubWords(String str, int index, String currWord)
{
if(index < 0) {
return (isWord(currWord));
}
return ( isWord(currWord) + getSubWords(str, index-1, str.charAt(index)+currWord) + getSubWords(str, index-1, currWord))
}
This can be done using DP
The recursion looks something like this:
Keep an index to the first and last char of the string say, beg and end
Now in every function call recurse using these two calls func(str, beg, end-1) and func(str, beg+1, end) , if beg==end return
int getSubWords(String str, int beg, int end) {
if(beg == end) {
return isWord(str.charAt(beg)) ;
}
return( isWord(str.substr(beg, end +1) + getSubWords(str, beg+1, end) + getSubstr(str, beg, end-1)));
}
This can be converted into DP by using a 2d memo array for keeping a count of the number of words found.
Repsherrifjenkins, Applications Developer at ASAPInfosystemsPvtLtd
I am Sherri from Richmond USA. I am working as a Clinical laboratory technician worker in P. Samuels Men's ...
Repwilliamchansen95, Computer Scientist at 247quickbookshelp
I am working as a manager in Lionel Kiddie City company. I really enjoy my job. I like to play ...
Rep
Repannehbell8, Quality Assurance Engineer at Globaltech Research
Build and maintain relationships with convention vendors. Resolve issues throughout meeting event timelines.Plan room layouts and event programs, schedule ...
If duplicates are detected we compare them word by word to make sure it is not a false positive.
- scorpionnishme May 12, 2014