Check if a palindromic string can be obtained by concatenating substrings split from same indices of two given strings | JavaScript program to implement the above approach ; iterate through the length if we could find a [ i ] = = b [ j ] we could increment I and decrement j ; else we could just break the loop as its not a palindrome type sequence ; we could concatenate the a ' s ▁ left ▁ part ▁ + b ' s right part in a variable a and a ' s ▁ right ▁ part + b ' s left in the variable b ; we would check for the palindrome condition if yes we print True else False ; Driver code
function rev ( str ) { var st = 0 ; var ed = str . length - 1 ; var s = str . split ( " " ) ; while ( st < ed ) { var temp = s [ st ] ; s [ st ] = s [ ed ] ; s [ ed ] = temp ; st ++ ; ed -- ; } return s . join ( ) ; } function check ( a , b , n ) { var i = 0 ; var j = n - 1 ; while ( i < n ) { if ( a [ i ] !== b [ j ] ) break ; i += 1 ; j -= 1 ; var xa = a . substring ( i , j + 1 - i ) ; var xb = b . substring ( i , j + 1 - i ) ; var XA = xa . split ( " " ) ; XA . sort ( ) . reverse ( ) ; var XB = xb . split ( " " ) ; XB . sort ( ) . reverse ( ) ; if ( xa === XA . join ( " " ) || xb === XB . join ( " " ) ) return true ; } return false ; } var a = " " ; var b = " " ; if ( check ( a , b , a . length ) || check ( b , a , a . length ) ) document . write ( " " ) ; else document . write ( " " ) ;