Count characters of a string which when removed individually makes the string equal to another string | Function to count characters from 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 B ; Traverse the B ; If N - M is equal to 1 and Y is less than or equal to X ; Print count of characters ; Print positions of the characters ; Otherwise ; Driver Code
def RemoveOneChar ( A , B , N , M ) : NEW_LINE INDENT X = 0 NEW_LINE Y = N - 1 NEW_LINE for i in range ( M ) : NEW_LINE INDENT if ( A [ X ] != B [ i ] ) : NEW_LINE INDENT break NEW_LINE DEDENT X += 1 NEW_LINE DEDENT for i in range ( M - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( A [ Y ] != B [ i ] ) : NEW_LINE INDENT break NEW_LINE DEDENT Y -= 1 NEW_LINE DEDENT if ( N - M == 1 and Y < X ) : NEW_LINE INDENT print ( X - Y + 1 ) NEW_LINE for i in range ( Y , X + 1 ) : NEW_LINE INDENT print ( i + 1 , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = " abaac " NEW_LINE B = " abac " NEW_LINE N = len ( A ) NEW_LINE M = len ( B ) NEW_LINE RemoveOneChar ( A , B , N , M ) NEW_LINE DEDENT