Coding Challenge Day 11- Problem 1: Palindrome String

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");
		}
	}

}

Download solution

Happy Learning!!

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close