the function of code is to find a palindrome substring at any index. code is running well and having no errors but the main problem is that it took time more than it specified. i tried every possible action but couldn't get the desired execution time
String palindrome(String s) throws Exception {
int x =0,y=0;
int max=0;
for (int i = 0,k=1; i < str.length() && k<=str.length();k++) {
String s = str.substring(i,k);
StringBuilder sb = new StringBuilder(s);
sb.reverse();
String reverse = sb.toString();
if (s.equals(reverse)) {
if (s.length() > max) {
max = s.length();
x = i;
y = k;
}
}
if (k==str.length()) {
++i;
k=i;
}
}
return str.substring(x,y);
}
the function of code is to find a palindrome substring at any index. code is running well and having no errors but the main problem is that it took time more than it specified. i tried every possible action but couldn't get the desired execution time