Trains the technique from
LeetCode 2273Find Resultant Array After Removing AnagramsThis 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 shelf holds the labels labels in order. While some label is a rearrangement of the label directly before it, the later of the two is taken off and the shelf closes up.
Return the labels that remain, in order. Whichever such pair is dealt with first, the shelf ends up the same.
Example 1
The second and third labels both rearrange the first, so both come off, and the last shares none of its letters.
Example 2
The repeats standing next to each other come off, but the final a follows a b so it stays.
Example 3
Neither label rearranges the other, so the shelf is untouched.
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 remove_anagrams(labels: list[str]) -> list[str]:public List<String> removeAnagrams(String[] labels)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.