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
function solve ( s , x , y ) { let res = 0 ; for ( let c of s ) { if ( c - ' ' == x ) { res ++ ; x = x + y ; y = x - y ; x = x - y ; } } if ( x != y && res % 2 == 1 ) -- res ; return res ; } function find_min ( s ) { let count = 0 ; for ( let i = 0 ; i < 10 ; i ++ ) { for ( let j = 0 ; j < 10 ; j ++ ) { count = Math . max ( count , solve ( s , i , j ) ) ; } } return count ; } let s = " " ; let n = s . length ; let answer = find_min ( s ) ; document . write ( n - answer ) ;