STRING problem

How to solve,
I tried but don’t know how to do
Please help (in C++)

https://practice.geeksforgeeks.org/problems/the-pattern-matcher/1/?track=module-2-arrays-and-strings&batchId=113

Start counting the number of x and y characters in the string. If you see an x character just after a y character, then check if the number of x character and y character are equal or not. If yes, proceed. Else return.
P.S. :- Beware of first element.

1 Like

Just keep 2 counters to count the occurrence of x and y separately. If an occurrence of x is encountered and counter of y is not 0 at this time, then just check if count of x is equal to count of y or not. If it is equal then reset the counters. Remember to check the counter condition even after coming out of the loop to handle cases like : yyyy
Here is my solution:

1 Like

Thanks