Loading...
Loading...
Loading...
A catalogue has n product codes made of lowercase letters. Two codes belong to the same group if one can be rearranged into the other. Print how many different groups there are. Comparing every pair of codes is too slow.
Example
Input
5 listen silent enlist google gogole
Output
2
Try the problem first. Open one hint at a time.
Comparing every pair of codes costs n² letter comparisons.
Two codes are in one group exactly when their sorted letters are equal. Use the sorted letters as a key.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor