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
function countStrings ( n , m , s ) { let ind = new Set ( ) ; for ( let j = 0 ; j < m ; j ++ ) { let mx = 0 ; for ( let i = 0 ; i < n ; i ++ ) mx = Math . max ( mx , ( s [ i ] [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ; for ( let i = 0 ; i < n ; i ++ ) if ( s [ i ] [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == mx ) ind . add ( i ) ; } return ind . size ; } let s = [ " " , " " , " " ] ; let m = s [ 0 ] . length ; let n = s . length ; document . write ( countStrings ( n , m , s ) ) ;