Check if a string can be split into 3 substrings such that one of them is a substring of the other two | Function to check if string S contains any character with frequency >= 3 or not ; Stores frequency of characters ; Iterate over the string ; Update the frequency of current character ; Iterate over the hash array ; If any character has frequency >= 3 ; Otherwise ; Driver Code
def freqCheck ( S , N ) : NEW_LINE INDENT hash = [ 0 ] * 26 NEW_LINE for i in range ( N ) : NEW_LINE INDENT hash [ ord ( S [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT for i in range ( 26 ) : NEW_LINE INDENT if ( hash [ i ] > 2 ) : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT DEDENT return " No " NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = " geekseekforgeeks " NEW_LINE N = len ( S ) NEW_LINE print ( freqCheck ( S , N ) ) NEW_LINE DEDENT