Loading
Loading
A chemistry database stores compound codes. Two codes describe the same compound when one is a rearrangement of the other.
Group the codes so that each group contains exactly the codes describing one compound. Return the number of distinct compounds.
codes = ["eat", "tea", "tan", "ate", "nat"]"eat" → "aet"new group"tea" → "aet"joins the first group"tan" → "ant"new group"ate" → "aet"joins the first group2Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n · k log k) time · O(n · k) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
{eat, tea, ate} and {tan, nat}.
Example 2