For each lowercase English alphabet find the count of strings having these alphabets | Function to find the countStrings for each letter [ a - z ] ; Initialize result as zero ; Mark all letter as not visited ; Loop through each strings ; Increment the global counter for current character of string ; Instead of re - initialising boolean vector every time we just reset all visited letter to false ; Print count for each letter ; Driver code ; Given array of strings ; Call the countStrings function
def CountStrings ( s ) : NEW_LINE INDENT size = len ( s ) NEW_LINE count = [ 0 ] * 26 NEW_LINE visited = [ False ] * 26 NEW_LINE for i in range ( size ) : NEW_LINE INDENT for j in range ( len ( s [ i ] ) ) : NEW_LINE INDENT if visited [ ord ( s [ i ] [ j ] ) - ord ( ' a ' ) ] == False : NEW_LINE INDENT count [ ord ( s [ i ] [ j ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT visited [ ord ( s [ i ] [ j ] ) - ord ( ' a ' ) ] = True NEW_LINE DEDENT for j in range ( len ( s [ i ] ) ) : NEW_LINE INDENT visited [ ord ( s [ i ] [ j ] ) - ord ( ' a ' ) ] = False NEW_LINE DEDENT DEDENT for i in range ( 26 ) : NEW_LINE INDENT print ( count [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = [ " i " , " will " , " practice " , " everyday " ] NEW_LINE CountStrings ( s ) NEW_LINE DEDENT