Loading...
Loading...
Loading...
Two words are anagrams when they use the same letters the same number of times, like listen and silent. Group the given product tags into anagram groups. Print the groups in the order their first word appears, and the words of a group in input order.
Example
Input
8 listen silent cat google act enlist tac elgoog
Output
listen silent enlist cat act tac google elgoog
listen, silent and enlist have the same letters; cat, act and tac; google and elgoog.
Try the problem first. Open one hint at a time.
Give every word a key: its letters in sorted order. Anagrams get the same key.
Arrays.sort(chars) sorts the letters; new String(chars) makes the key.
Use a LinkedHashMap<String, List<String>> so the groups come out in order of first appearance.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor