Encrypted password
InterviewTime limit2sMemory limit128 MB
Decide whether the original password's letters can be rearranged to match a contiguous block inside the encrypted password.
- Level
Medium5 of 10
- Topics
- Sliding window, Hash map, String
- Solved
- No attempts yet
Problem
Someone built a new encryption algorithm. Assume every password is made of lowercase letters only.
Encryption goes like this.
- Swap the letters at two different positions of the password. You may skip this step, or repeat it as many times as you want.
- Add zero or more characters in front of the result of step 1.
- Add zero or more characters behind the result of step 2.
The result of step 3 is the encrypted password.
Cheongho encrypted every password he used with this algorithm. He did it by hand, so he may have slipped somewhere, and he wants a program that checks whether the encryption came out right.
Given an encrypted password and the original password, decide whether the encrypted password can be the result of encrypting the original password with the algorithm above.
Input
The first line has the number of test cases . ()
Each test case takes two lines. The first line holds the encrypted password and the second line holds the original password.
Both strings are made of lowercase letters only, and each has length at least and at most . The encrypted password is never shorter than the original password.
Output
Print one line per test case. Print YES if encrypting the original password with the algorithm can produce the given encrypted password, and NO if it cannot.