Why does this not work

I tried simple pointer approach instead of DP
Can you explain why this doesn’t work

int al=a.length();
int bl=b.length();
int l=ab.length();
if (l!=al+bl) return 0;
int j=0,k=0,i;
for (i=0; i<l; i++){
    if (j<al && ab[i]==a[j]){
    else if (k<bl && ab[i]==b[k]){
    else return 0;
return 1;
Click here to start solving coding interview questions