J.P. Morgan Interview Question

grouping anagrams in sorted way