2
public boolean checkPalindromeFormation(String a, String b) {3
// either way of split should give us a palindrome4
return cut(a, b) || cut(b, a);7
// method to match letters from both ends8
private boolean cut(String a, String b) {9
int i = 0, j = a.length() - 1;10
// converge from both ends till we have same letters11
while (i < j && a.charAt(i) == b.charAt(j)) {16
// the case when we surpassed the mid point from both ends17
if (i >= j) return true;18
// the case when there is still a substring left in between19
// or say we didn't reach the mid point20
// we will check if that substring is a palindrome or not21
return isPalindrome(a, i, j) || isPalindrome(b, i, j);24
// method to check if a string is palindrome25
private boolean isPalindrome(String s, int i, int j) {27
if (s.charAt(i++) != s.charAt(j--)) {