Check if a string can be split into 3 substrings such that one of them is a substring of the other two | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; string freqCheck ( string S , int N ) { int hash [ 26 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { hash [ S [ i ] - ' a ' ] ++ ; } for ( int i = 0 ; i < 26 ; i ++ ) { if ( hash [ i ] > 2 ) { return " Yes " ; } } return " No " ; } int main ( ) { string S = " geekseekforgeeks " ; int N = S . length ( ) ; cout << freqCheck ( S , N ) ; return 0 ; }