I think I had squared subsequence and I did. Now placed at 12th!
The idea is to try all possible ways to break s[] into s1[] and s2[] and count the number of equal subseq in both s1[] and s2[] with the last char of s1 matched.
The recurrence is common[n1][n2] = common[n1][n2-1] + common[n1-1][n2] - common[n1-1][n2-1]
we add back common[n1-1][n2-1] if s1[n1-1] match s2[n2-1].
# Status Signal Time
1 Passed Your code produced correct output for this testcase. 0.07061
2 Passed Your code produced correct output for this testcase. 0.070552
3 Passed Your code produced correct output for this testcase. 0.564724
4 Passed Your code produced correct output for this testcase. 0.503675
5 Passed Your code produced correct output for this testcase. 0.383056
6 Passed Your code produced correct output for this testcase. 0.514264
7 Passed Your code produced correct output for this testcase. 0.695142
8 Passed Your code produced correct output for this testcase. 0.524266
9 Passed Your code produced correct output for this testcase. 0.556575
10 Passed Your code produced correct output for this testcase. 0.473493
Rank Hacker Country Score Submissions Solved
11 diogoaos Brazil 811.00 56 21
12 lantimilan USA 784.00 79 19
13 liangjiaxing Canada 778.00 50 19
14 jin.ubc Canada 763.00 42 20
15 uwi Japan 760.00 39 19
15 megaterik Belarus 760.00 102 22
17 hadi Iran 740.00 48 19
18 Amtrix Germany 735.00 20 19
19 chhung6 Hong Kong 732.00 76 19
20 ttim Kazakhstan 730.00 95 19
Subscribe to:
Post Comments (Atom)
hi,i didn,t understand what is common[n1][n2] can you please elaborate..and also please see the substring difference problem(interviewstreet) i posted a comment on it.
ReplyDeletehi,i didn't understand your solution can you please elaborate..
ReplyDeletealso see substring difference problem there i poste a comment
on it
hi,have you solved billboards problem in interviewstreet?if so can you please give me an idea.I think about that problem about 2 and half days but i am not getting any ideas.please give some help if possible
ReplyDeleteHii siva,i also worked on billboards problem,after submitting my code,4/10 test cases passed and Segmentation fault for rest of the test cases...
ReplyDelete:P
I have to develop memory and runnig time skills :)
You can contact me @ vijaykumarch.iitkgp@gmail.com
ReplyDeleteYou can also try to minimize the sum of blocks you throw away, and there is some way to keep track of minimum within a sliding window which is O(1) time.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteIs it a n^2 algorithm ?
ReplyDeleteO(n) for sure, otherwise will TLE
DeleteActually I doubt it's O(n) since `common` is a 2D matrix. But O(n^2) shouldn't TLE for n=200.
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteHI Lyan,
ReplyDeleteI have been trying hard on this problem for quite sometime. Can you please kindly help me on this....I have written the following code , but it is failing in some of the cases.
int calculateSquareSubsequence(String str)
{
int len = str.length();
int max=0;
int res[][] = new int[len+1][len+1];
int i,j;
for(i=0;i<=len;++i)
res[i][0]=1;
for(j=0;j<=len;++j)
res[0][j]=1;
for(i=1;i<=len;i++)
for(j=i;j<=len;j++)
{
if(j==i)
res[i][j]=1;
else if(str.charAt(i-1) == str.charAt(j-1))
res[i][j]= res[i][j-1]+res[i-1][j];
else
res[i][j]= res[i][j-1]+res[i-1][j]-res[i-1][j-1];
}
/*for(i=0;i<=len;++i){
for(j=0;j<=len;++j)
System.out.print(res[i][j] + " ");
System.out.println();
}*/
max = res[0][len];
for(i=1;i<=len;++i)
if(max < res[i][len])
max = res[i][len];
return max-1;
}
Regards
Praneeth