Hello! So I’m doing a 30 day coding challenge where I solve around 3-5 questions per day and thought of posting them here on my blog so that you guys can join the challenge too!
Welcome to Coding challenge Day 11: Problem 1! Be sure to post your answers, queries etc in the comments!
Problem: Given an array of characters formed with a’s and b’s. The string is marked with special character X which represents the middle of the list (for example: abbbaaa….. aaaabbXaaaababab…….abbbbaab).Check whether the string is palindrome.
Sample input: ababXbaba
Output: Palindrome
Solution: abXbaba
Output: Not palindrome
package string;
public class Program009palindrome_string {
public static void main (String [] args){
String str= "ababXbaba";
char[] s= str.toCharArray();
int i=0, j=s.length-1;
while(i<j && s[i]==s[j]){
i++;
j--;
}
if(i<j){
System.out.println("Not palindrome");
}
else{
System.out.println("Palindrome");
}
}
}
Happy Learning!!