Minimum number of Appends needed to make a string palindrome | Checking if the string is palindrome or not ; single character is always palindrome ; pointing to first character ; pointing to last character ; Recursive function to count number of appends ; Removing first character of string by incrementing base address pointer . ; Driver code
function isPalindrome ( str ) { let len = str . length ; if ( len == 1 ) return true ; let ptr1 = 0 ; let ptr2 = len - 1 ; while ( ptr2 >= ptr1 ) { if ( str [ ptr1 ] != str [ ptr2 ] ) return false ; ptr1 ++ ; ptr2 -- ; } return true ; } function noOfAppends ( s ) { if ( isPalindrome ( s . split ( " " ) ) ) return 0 ; s = s . substring ( 1 ) ; return 1 + noOfAppends ( s ) ; } let s = " " ; document . write ( noOfAppends ( s ) ) ;