Problem link
It should be noted that if Polycarp press a key once, it's possible to appear one, two or more letters. So, if Polycarp press a key times, letter will appear at least times. Also, pressing a particular key not always prints same number of letters. So the possible correct solution is followed:
For both words and we should group consecutive identical letters with counting of the each group size. For ex, there 4 groups in the word "aaabbcaa": . For performance you should keep every group as the letter (char) and the group size (int).
Then, if the number of groups in word isn't equal to the number of groups in word , then can not be printed during typing of . Let's go through array with such groups and compare the -th in the word with the -th in the word . If letters in groups are different, answer is NO. If the group in are greater than group in , answer is NO. Answer is YES in all other cases.
Every string can be splitted into such groups by one loop. So, the total time complexity is
A solution in c++
0 Comments
If you have any doubts, Please let me know