Check if a string contains two non overlapping sub | Java 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
class GFG { static boolean isValid ( String s ) { if ( ( s . indexOf ( " geek " ) != - 1 ) && ( s . indexOf ( " keeg " , s . indexOf ( " geek " ) + 4 ) != - 1 ) ) return true ; return false ; } public static void main ( String args [ ] ) { String s = " geekeekeeg " ; if ( isValid ( s ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }