Unique Sub Arrays

Given a collection of integers nums that might contain duplicates, return all possible sub-arrays of nums.

Note: The solution set must not contain duplicate subsets.

Ex.1 nums = {1, 2, 2}

0: 2
1:
2: 1
3: 1  2  2
4: 1  2
5: 2  2

Ex.2  nums = {1, 2, 3}

0: 2
1:
2: 1  2  3
3: 1
4: 3
5: 1  2
6: 2  3

The Idea: Define a hash for an unordered_setof vectors. Then double loop through the collection for every possible subarray size.

Complexity: O(n^2) time and O(2*n^2) space

Last updated

Was this helpful?