Removing Pairs
InterviewTime limit2sMemory limit512 MB
Decide whether string s can be obtained from string t by repeatedly deleting two adjacent characters, where each deletion removes any neighboring pair.
- Level
Medium5 of 10
- Topics
- String, Dynamic programming, Greedy, Two pointers
- Solved
- No attempts yet
Problem
The pair removal operation removes two adjacent characters from a string. For example, from the string "abcd" we can obtain "ab", "ad", and "cd" by pair removal.
You are given a string . You can apply pair removal any number of times. Is it possible to obtain the string ?
Input
The first line contains the string , and the second line contains the string (). Both strings are composed of lowercase letters of the English alphabet.
Output
Print "YES" if it is possible to obtain from using pair removal, or "NO" otherwise.
Hint
In the first test, one of the possible pair removal sequences is the following:
abcbcxddaabcxddaabcxaaxa