Length of largest subsequence consisting of a pair of alternating digits |  ; Function to find the length of the largest subsequence consisting of a pair of alternating digits ; Variable initialization ; Nested loops for iteration ; Check if i is not equal to j ; Initialize length as 0 ; Iterate from 0 till the size of the string ; Increment length ; Increment length ; Update maxi ; Check if maxi is not equal to 1 the print it otherwise print 0 ; Given string ; Function call
/ *Js program for the above approach  / * function largestSubsequence ( s ) { let maxi = 0 ; let prev1 ; for ( let i = 0 ; i < 10 ; i ++ ) { for ( let j = 0 ; j < 10 ; j ++ ) { if ( i != j ) { let len = 0 ; prev1 = String ( j ) ; for ( let k = 0 ; k < s . length ; k ++ ) { if ( s [ k ] == String ( i ) && prev1 == String ( j ) ) { prev1 = s [ k ] ; len ++ ; } else if ( s [ k ] == String ( j ) && prev1 == String ( i ) ) { prev1 = s [ k ] ; len ++ ; } } maxi = Math . max ( len , maxi ) ; } } } if ( maxi != 1 ) document . write ( maxi , ' ' ) ; else document . write ( 0 , ' ' ) ; } let s = " " ; largestSubsequence ( s ) ;