Check Similar Passwords
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's December 2023 OA asks you to validate password similarity by checking if an old password becomes a subsequence of a transformed new password. The transformation rule is simple: pick any character indices in the new password and shift each one forward by one position in the alphabet (z wraps to a). You're not transforming the old password. You're checking if the old password can be found as a subsequence in the new password after you've optimally chosen which characters to shift. StealthCoder can feed you the exact subsequence logic you need when you're live.
The problem
Amazon would like to enforce a password policy that when a user changes their password, the new password cannot be similar to the current one. To determine whether two passwords are similar, they take the new password, choose a set of indices and change the characters at these indices to the next cyclic character exactly once. Character 'a' is changed to "b", 'b' to 'c' and so on, and 'z' changes to 'a'. The password is said to be similar if after applying the operation, the old password is a subsequence of the new password. The developers come up with a set of n password change requests, where newPasswords denotes the array of new passwords and oldPasswords denotes the array of old passwords. For each pair newPasswords[i] and oldPassword[i], return "YES" if the passwords are similar, that is newPasswords[i] becomes a subsequence of oldPasswords[i] after performing the operations, and "NO" otherwise. Note A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. Function Description Complete the function checkSimilarPasswords in the editor. checkSimilarPasswords has the following parameters: Returns string[n]: the ith string represents the answer to the ith pair of passwords.
Reported by candidates. Source: FastPrep
Pattern and pitfall
This is a greedy two-pointer problem disguised as a character-shifting puzzle. The key insight: for each character in the old password, you want to find a matching character in the new password that either matches exactly or can be shifted to match (meaning the character at that position in new password, when incremented cyclically, equals the current old password character). Iterate through the old password with one pointer, iterate through the new password with another, and advance both pointers whenever you find a match. The trick candidates miss is treating the shift operation as optional per character, not mandatory. If you blank on the greedy approach during the live OA, StealthCoder will show you the two-pointer skeleton instantly.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Check Similar Passwords cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as is subsequence. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Check Similar Passwords FAQ
Do I have to shift every character in the new password?+
No. You choose which indices to shift. For each position in the new password, you decide independently whether to apply the cyclic shift or leave it unchanged. This freedom is what makes the greedy approach work. You're hunting for a subsequence match by selecting the best characters to shift.
What does 'subsequence' mean in this context?+
Old password characters must appear in the new password in the same order, but not necessarily consecutively. You can skip characters in the new password. Once you match a character from old to new, you move forward in both strings. Backtracking in new password is not allowed.
Is this asking if old is a substring or a subsequence?+
Subsequence, not substring. Substrings must be consecutive. You can have gaps in the new password between matched characters, as long as the old password characters appear left-to-right. That's why greedy works: match each old char to the earliest available new char.
How hard is the subsequence check itself?+
Very straightforward. Two pointers, one pass through new password. For each old password character, scan the new password until you find a match (either exact or shifted). Increment both pointers and continue. Linear time, no DP needed.
Can I prepare for this in 48 hours?+
Yes. Understand cyclic character increment (a->b, z->a), then practice basic greedy subsequence matching on a few examples. The problem is less about algorithmic complexity and more about correctly implementing the match logic. Trace through one example by hand first.