Check if a string contains two non overlapping sub | C ++ implementation of the approach ; Function that returns true if s contains two non overlapping sub strings " geek " and " keeg " ; If " geek " and " keeg " are both present in s without over - lapping and " keeg " starts after " geek " ends ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isValid ( char s [ ] ) { char * p ; if ( ( p = strstr ( s , " geek " ) ) && ( strstr ( p + 4 , " keeg " ) ) ) return true ; return false ; } int main ( ) { char s [ ] = " geekeekeeg " ; if ( isValid ( s ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }