Count of characters in str1 such that after deleting anyone of them str1 becomes str2 | Function to return the count of required indices ; Solution doesn 't exist ; Find the length of the longest common prefix of strings ; Find the length of the longest common suffix of strings ; If solution does not exist ; Return the count of indices ; Driver code
def Find_Index ( str1 , str2 ) : NEW_LINE INDENT n = len ( str1 ) NEW_LINE m = len ( str2 ) NEW_LINE l = 0 NEW_LINE r = 0 NEW_LINE if ( n != m + 1 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT for i in range ( m ) : NEW_LINE INDENT if str1 [ i ] == str2 [ i ] : NEW_LINE INDENT l += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT i = n - 1 NEW_LINE j = m - 1 NEW_LINE while i >= 0 and j >= 0 and str1 [ i ] == str2 [ j ] : NEW_LINE INDENT r += 1 NEW_LINE i -= 1 NEW_LINE j -= 1 NEW_LINE DEDENT if l + r < m : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT i = max ( n - r , 1 ) NEW_LINE j = min ( l + 1 , n ) NEW_LINE return ( j - i + 1 ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str1 = " aaa " NEW_LINE str2 = " aa " NEW_LINE print ( Find_Index ( str1 , str2 ) ) NEW_LINE DEDENT