Find a palindromic string B such that given String A is a subsequense of B | Function to check if a string is palindrome ; Reversing a string ; Check if reversed string is equal to given string ; Function to find a palindromic string B such that given String A is a subsequense of B ; Reversing the string A ; If the string A is already a palindrome return A ; Else return B ; Swap values of left and right ; Driver Code
function checkPalindrome ( s ) { let x = reverse ( s ) ; return x == ( s ) ; } function findStringB ( A ) { let B = reverse ( A ) ; B = B + A ; if ( checkPalindrome ( A ) ) { return A ; } return B ; } function reverse ( input ) { let temparray = input . split ( " " ) ; let left , right = 0 ; right = temparray . length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { let temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return ( temparray ) . join ( " " ) ; } let A = " " ; document . write ( findStringB ( A ) ) ;