Trains the technique from
LeetCode 1528Shuffle StringThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A ticket code came off a faulty printer with its characters out of order, but every character was tagged with the position it belongs in.
You are given code, the scrambled string, and slots of the same length. The character code[i] belongs at position slots[i] of the restored code, with positions counted from 0.
Return the restored code.
Example 1
The "d" is tagged for position 3, the "c" for position 2, the "b" for position 1 and the "a" for position 0, which spells "abcd".
Example 2
The "w" goes to position 1, the "x" to position 2 and the "y" to position 0, giving "ywx".
Example 3
Positions 2 and 3 take the "p" and the "i", while positions 0 and 1 take the two "l" characters, spelling "llpi".
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def restore_code(code: str, slots: list[int]) -> str:public String restoreCode(String code, int[] slots)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.