Given an array of strings, remove each string that is an anagram of an earlier string, then return the remaining array in sorted order.
str = ['code', 'doce', 'ecod', 'framer', 'frame']
code
anddoce
are anagrams. Removedoce
from the array and keep the first occurrencecode
in the array.code
andecod
are anagrams. Removeecod
from the array and keep the first occurrencecode
in the array.code
andframer
are not anagrams. Keep both strings in the array.framer
andframe
are not anagrams due to the extrar
inframer
. Keep both strings in the array.- Order the remaining strings in ascending order:
['code','frame','framer']
.