Hi,
One of my friends pointed me towards this site: *www.interviewstreet.com/challenges
It is like a programming leaderboard, wherein you solve problems and get ranked. So, I have started this thread to discuss challenges, their algorithms, your rank/score, what you tackled lately etc.
I would ask you to avoid putting up your code so that everyone can rack their brains
EDIT: I've tackled this problem today:
However, the code I wrote in Java seems to pass only 4 out of 10 test cases. Since they have not shown what extra testcases they are using to test, I cannot know what went wrong. So, referring to the above problem, what else, according to you guys, should I test for?
PS: The code passes the above mentioned test cases successfully.
One of my friends pointed me towards this site: *www.interviewstreet.com/challenges
It is like a programming leaderboard, wherein you solve problems and get ranked. So, I have started this thread to discuss challenges, their algorithms, your rank/score, what you tackled lately etc.
I would ask you to avoid putting up your code so that everyone can rack their brains
EDIT: I've tackled this problem today:
For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" is 2, while the similarity of strings "aaa" and "aaab" is 3.
Calculate the sum of similarities of a string S with each of it's suffixes.
Input:
The first line contains the number of test cases T. Each of the next T lines contains a string each.
Output:
Output T lines containing the answer for the corresponding test case.
Constraints:
1 <= T <= 10
The length of each string is at most 100000 and contains only lower case characters.
Sample Input:
2
ababaa
aa
Sample Output:
11
3
Explanation:
For the first case, the suffixes of the string are "ababaa", "babaa", "abaa", "baa", "aa" and "a". The similarities of each of these strings with the string "ababaa" are 6,0,3,0,1,1 respectively. Thus the answer is 6 + 0 + 3 + 0 + 1 + 1 = 11.
For the second case, the answer is 2 + 1 = 3.
However, the code I wrote in Java seems to pass only 4 out of 10 test cases. Since they have not shown what extra testcases they are using to test, I cannot know what went wrong. So, referring to the above problem, what else, according to you guys, should I test for?
PS: The code passes the above mentioned test cases successfully.