source and target made of lowercase English letters, and a number moves. The goal is to turn source into target in at most moves moves.
Moves are numbered from 1. On move number i you may do one of two things:
- pick a position in source that has never been picked before and shift its letter forward in the alphabet by exactly i steps (after z comes a again);
- skip the move.
Each position can be picked at most once. Return True if source can be turned into target, and False otherwise. The strings may differ in length, in which case it is impossible.source="cat", target="dog", moves=20 → True
The shifts are c→d by 1, a→o by 14 and t→g by 13 (wrapping past z). They are all different and the largest is 14 ≤ 20, so moves 1, 13 and 14 do the job.
source="aaa", target="bbb", moves=27 → False
Each letter needs a shift of 1. The first can use move 1, the second move 27 (a full lap plus one), but the third would need move 53 > 27.
source="go", target="go", moves=0 → True
The strings already match, so no moves are needed.
source="cat", target="dog", moves=20
True
Run checks the first 3 tests in your browser. Submit checks all 122 tests on the server, hidden ones included.