Can anyone please help me to solve below problem
Check whether the string is palindrome or not. If the string is not palindrome then make it palindrome.
eg: input: ABC, output: ABCBA
I know how to check whether string is palindrome or not. Please help in the second part of the question.
in best case, better if we can achieve below result also
eg: input: AAB, output: ABA
for 1st exmaple i tried this approach
LinkedList <String> q = new LinkedList<>();
//String [] ar ={"a","b","c","b","d"};
String [] ar ={"A","B","C"};;
int mid=ar.length/2;
q.addFirst(ar[mid]);
for(int i= mid, j=mid; i>=0&&j<ar.length;){
if(j+1==ar.length && i-1==-1)
break;
q.addFirst(ar[i-1]);
if(ar[i-1]!=ar[j+1]){
q.addLast(ar[i-1]);
q.addLast(ar[j+1]);
q.addFirst(ar[j+1]);
}else{
q.addLast(ar[j+1]);
}
j++;
i--;
}