entries. While you can, repeat this step: pick a word that has a left neighbour which is its anagram (the same letters in the same quantities, possibly rearranged) and delete that word from the list.
Return the list that remains once nothing more can be deleted. It can be shown that the result does not depend on the order of deletions.entries=['stop', 'pots', 'tops', 'spot', 'go', 'og', 'stop'] → ['stop', 'go', 'stop']
"pots", "tops" and "spot" each match their left neighbour letter for letter and get removed, then "og" goes the same way. The final "stop" stays: its left neighbour is now "go".
entries=['ab', 'abb', 'bab'] → ['ab', 'abb']
"ab" and "abb" are not anagrams: they have a different number of b's. "bab" is an anagram of "abb", so it is removed.
entries=['moon'] → ['moon']
entries) ≤ 10⁵entries[i]) ≤ 10entries=['stop', 'pots', 'tops', 'spot', 'go', 'og', 'stop']
['stop', 'go', 'stop']
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.