Check given string is oddly palindrome or not | Set 2 | Function to check if string formed by odd indices is palindromic or not ; Check if length of OddString odd , to consider edge case ; Push odd index character of first half of str in stack ; Middle element of odd length palindromic string is not compared ; If stack is empty then return true ; Driver Code ; Given string
function isOddStringPalindrome ( str , n ) { var oddStringSize = parseInt ( n / 2 ) ; var lengthOdd = ( ( oddStringSize % 2 == 1 ) ? true : false ) ; var s = [ ] ; var i = 1 ; var c = 0 ; while ( i < n && c < parseInt ( oddStringSize / 2 ) ) { s . push ( str [ i ] ) ; i += 2 ; c ++ ; } if ( lengthOdd ) i = i + 2 ; while ( i < n && s . length > 0 ) { if ( s [ s . length - 1 ] == str [ i ] ) s . pop ( ) ; else break ; i = i + 2 ; } if ( s . length == 0 ) return true ; return false ; } var N = 10 ; var s = " " ; if ( isOddStringPalindrome ( s , N ) ) document . write ( " " ) ; else document . write ( " " ) ;