Number of strings that satisfy the given condition | Function to return the count of valid strings ; Set to store indices of valid strings ; Find the maximum digit for current position ; Add indices of all the strings in the set that contain maximal digit ; Return number of strings in the set ; Driver code
def countStrings ( n , m , s ) : NEW_LINE INDENT ind = dict ( ) NEW_LINE for j in range ( m ) : NEW_LINE INDENT mx = 0 NEW_LINE str1 = s [ j ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT mx = max ( mx , int ( str1 [ i ] ) ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if int ( str1 [ i ] ) == mx : NEW_LINE INDENT ind [ i ] = 1 NEW_LINE DEDENT DEDENT DEDENT return len ( ind ) NEW_LINE DEDENT s = [ "223" , "232" , "112" ] NEW_LINE m = len ( s [ 0 ] ) NEW_LINE n = len ( s ) NEW_LINE print ( countStrings ( n , m , s ) ) NEW_LINE