Minimum digits to be removed to make either all digits or alternating digits same | Function to find longest possible subsequence of s beginning with x and y ; Iterate over the string ; Increment count ; Swap the positions ; Return the result ; Function that finds all the possible pairs ; Update count ; Return the answer ; Given string s ; Find the size of the string ; Function call ; This value is the count of minimum element to be removed
def solve ( s , x , y ) : NEW_LINE INDENT res = 0 NEW_LINE for c in s : NEW_LINE INDENT if ( ord ( c ) - ord ( '0' ) == x ) : NEW_LINE INDENT res += 1 NEW_LINE x , y = y , x NEW_LINE DEDENT DEDENT if ( x != y and res % 2 == 1 ) : NEW_LINE INDENT res -= 1 NEW_LINE DEDENT return res NEW_LINE DEDENT def find_min ( s ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT for j in range ( 10 ) : NEW_LINE INDENT count = max ( count , solve ( s , i , j ) ) NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT s = "100120013" NEW_LINE n = len ( s ) NEW_LINE answer = find_min ( s ) NEW_LINE print ( n - answer ) NEW_LINE