You are given r rows, each containing exactly c integers. Two rows belong to the same group when they contain the same values with the same multiplicities, regardless of order (i.e. they are equal as multisets). Count how many distinct groups the rows form.
Line 1: two integers r and c.
Next r lines: each contains c space-separated integers, one row.
A single integer: the number of distinct multiset groups.
Example 1
Input
3 3 1 2 3 3 2 1 1 1 2
Expected
2
Explanation
Rows 1 and 2 are both the multiset {1,2,3}, so they group together. Row 3 is {1,1,2}, a different group. That is 2 distinct groups.
Example 2
Input
2 2 5 5 5 5
Expected
1
Explanation
Both rows are the multiset {5,5}, forming a single group, so the answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →