AmazonOA #359
Check Similar Passwords (Also for Fungile)
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersStrings
For each request, choose any positions in new and change each of them once to its cyclic successor letter, or choose none. Determine whether old can become a subsequence of the modified new; a position cannot be changed more than once. The successor of z is a.
Input
The input is a JSON two-dimensional array whose items are [new,old]. Original: 1..10 requests, a total length of all new and old strings≤200000, and old length≤new length in each item. Characters are lowercase letters, following the original cyclic a..z definition; there is no non-empty requirement on individual strings, so empty strings are allowed.
Output
Output YES or NO on its own line for each request.
Example 1
Input:
[["baacbab","abdbc"],["accdb","ach"],["baacba","abb"]]
Output:
YES
NO
YES
Example 2
Input:
[["aaccbbee","bdbf"],["aab","aee"]]
Output:
YES
NO
Example 3
Input:
[["z","a"],["",""]]
Output:
YES
YES
Example notes
The public outputs are YES/NO/YES, YES/NO and YES/YES. The second paragraph of the original statement reverses the direction of the subsequence; this site restores the direction that agrees with the first paragraph, with old length≤new length, and with all examples.
Editorial
Loading solution…