Count characters of a string which when removed individually makes the string equal to another string | Function to count characters from string A whose removal makes the strings A and B equal ; Stores the index of the longest prefix ; Stores the index of the longest suffix ; Traverse the string B ; Traverse the string B ; If N - M is equal to 1 and Y is less than or equal to X ; Print the count of characters ; Print the positions of the characters ; Otherwise ; Driver Code
function RemoveOneChar ( A , B , N , M ) { var X = 0 ; var Y = N - 1 ; var i ; for ( i = 0 ; i < M ; i ++ ) { if ( A [ X ] != B [ i ] ) break ; X ++ ; } for ( i = M - 1 ; i >= 0 ; i -- ) { if ( A [ Y ] != B [ i ] ) break ; Y -- ; } if ( N - M == 1 && Y < X ) { document . write ( X - Y + 1 + " " ) ; for ( i = Y ; i <= X ; i ++ ) document . write ( i + 1 + " " ) ; document . write ( " " ) ; } else document . write ( - 1 ) ; } var A = " " ; var B = " " ; var N = A . length ; var M = B . length ; RemoveOneChar ( A , B , N , M ) ;