Check if a string can be split into 3 substrings such that one of them is a substring of the other two | Java program for the above approach ; 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
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static String freqCheck ( String S , int N ) { int hash [ ] = new int [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { hash [ S . charAt ( i ) - ' a ' ] ++ ; } for ( int i = 0 ; i < 26 ; i ++ ) { if ( hash [ i ] > 2 ) { return " Yes " ; } } return " No " ; } public static void main ( String [ ] args ) { String S = " geekseekforgeeks " ; int N = S . length ( ) ; System . out . println ( freqCheck ( S , N ) ) ; } }