Last remaining character after repeated removal of the first character and flipping of characters of a Binary String | Function to find the last removed character from the string ; Stores length of the string ; Base Case : ; If the second last character is '0' ; If the second last character is '1' ; Driver Code
function lastRemovedCharacter ( str ) { var n = str . length ; if ( n == 1 ) return str [ 0 ] ; if ( str [ n - 2 ] == " " ) { return " " - str [ n - 1 ] + " " ; } else return str [ n - 1 ] ; } var str = " " ; document . write ( lastRemovedCharacter ( str ) ) ;