Number of strings that satisfy the given condition | C # implementation of the approach ; 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
using System ; using System . Collections . Generic ; class GfG { static int countStrings ( int n , int m , String [ ] s ) { HashSet < int > ind = new HashSet < int > ( ) ; for ( int j = 0 ; j < m ; j ++ ) { int mx = 0 ; for ( int i = 0 ; i < n ; i ++ ) mx = Math . Max ( mx , ( int ) ( s [ i ] [ j ] - '0' ) ) ; for ( int i = 0 ; i < n ; i ++ ) if ( s [ i ] [ j ] - '0' == mx ) ind . Add ( i ) ; } return ind . Count ; } public static void Main ( ) { String [ ] s = { "223" , "232" , "112" } ; int m = s [ 0 ] . Length ; int n = s . Length ; Console . WriteLine ( countStrings ( n , m , s ) ) ; } }