I have written the which works fine.
public class Palindrom {
public static boolean isPalindrom(String s){
char[] c = s.toCharArray();
for(int i =0;i<=(s.length()-1)/2;i++){
if(c[i]!=c[(s.length()-1)-i]){
return false;
}
}
return true;
}
public static void main(String[] args){
String s="aba";
int n=3;
for(int j=0;j<s.length()-1;j++){
for(int i =j+n;i<s.length()+1;i++){
if(isPalindrom(s.substring(j,i))){
System.out.println(s.substring(j,i));
}
}
}
}
}
The complexity of the code I think is o(n^3). Please correct me if I am wrong. Somebody please confirm this is correct
Also can anybody tell me how to solve this problem using DP(Dynamic programming)?