My solution to this problem is working fine in codechef’s online IDE and also I got accepted. But when I run it on my local pc with ubuntu, it s giving different output for the same test case. Can anyone figure out what is happening.
Check out whether string inputs are fine or not on your system.
Can you give the testcase where it provides different output on your pc?
Even the test cases given in the problem statement is producing different output on my system.
1
john johny
This test case is giving output “YES” on codechef’s IDE and “NO” on my system.
I got it. You didn’t initialize the variable j as 0 in the function isSubsequence. Not initializing a variable has varying behavior depending on the compiler. In this case, the codechef IDE probably set it to 0, while your compiler in ubuntu did not.
int isSubSequence(char s1[],char s2[],int l1,int l2){
int i,j=0;
for(i=0;i<l1 && j<l2;i++){
if(s2[j]==s1[i])j++;
}
if(j==l2)return 1;
return 0;
}
Your welcome and good luck!
1 Like