Trains the technique from
LeetCode 1047Remove All Adjacent Duplicates In 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 jacquard loom runs off a punched tape. Every hole in the tape carries one shed code, written as a single lowercase letter, and the loom reads the codes in order starting from the head of the tape.
The loom has a quirk. Whenever two holes sitting side by side carry the same code, the second one undoes the first, so the loom throws that pair away. The tape then closes up around the gap, which can bring two codes that were held apart into contact, and those two may cancel in their turn. The loom goes on discarding pairs for as long as it can find one.
Given the tape as the string tape, return the codes still punched on it once no two neighbouring holes carry the same code. The settled tape can come back empty. Whichever pair the loom happens to discard first, the codes it finishes with are the same, so there is a single answer to report.
Example 1
The pair of n codes goes first, which leaves the two m codes touching, and they go next. What is left is p followed by q, and those two differ.
Example 2
The r pair goes, then the t pair, which brings the two s codes together and they go as well, leaving u on its own.
Example 3
The v pair goes, then the d pair, then the k pair, so the loom is left with a bare tape.
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 settle_the_loom_tape(tape: str) -> str:public String settleTheLoomTape(String tape)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.