Check if two same sub | C ++ program to Check if similar subsequences exist or not ; Function to check if similar subsequences occur in a string or not ; iterate and count the frequency ; freq [ s [ i ] - ' a ' ] ++ ; counting frequency of the letters ; check if frequency is more than once of any character ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( string s , int l ) { int freq [ 26 ] = { 0 } ; for ( int i = 0 ; i < l ; i ++ ) { } for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] >= 2 ) return true ; } return false ; } int main ( ) { string s = " geeksforgeeks " ; int l = s . length ( ) ; if ( check ( s , l ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }