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
function freqCheck ( S , N ) { let hash = new Array ( 26 ) . fill ( 0 ) for ( let i = 0 ; i < N ; i ++ ) { hash [ S . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ] += 1 } for ( let i = 0 ; i < 26 ; i ++ ) { if ( hash [ i ] > 2 ) { return " " } } return " " } let S = " " let N = S . length document . write ( freqCheck ( S , N ) )