I know there are better more optimized solution but since i was approaching this que with dp so i first came with recursive solution which is not working in some cases can
heres the code please can anyone tell whats issue and whats correct recursive code
public static int solveRecursive(String x,int i,int f) {
if(i>f){
return 0;
}
if(x.charAt(i)==x.charAt(f)){
//
if(i==f){
return 1;
}
else{
return Math.max(solveRecursive(x,i+1,f-1)+2,Math.max(solveRecursive(x,i,f-1)+1,solveRecursive(x,i+1,f)+1));
}
}
else{
return Math.max(solveRecursive(x,i,f-1)+1,solveRecursive(x,i+1,f)+1);
}
}