Let's now discuss the time and space complexity of the approach that we just now discussed.
So the time and space complexity of this solution is going to be similar to the time and space complexity
of the Subset's question, because in the worst case, it's possible that there is no repetition in
the input array which is given to us.
So over here notice that n is equal to four.
There are four elements in the input array and two to the power n in this case is equal to 16.
But we are only having 12 subsets.
We only have 12 subsets because we have removed duplicates.
But again in the worst case, if there are no duplicates, we would still have two to the power n subsets,
and we are doing n calls to the recursive function to get those two to the power n subsets.
And in each call we are doing constant time operations.
So the time complexity of this solution is O of n into two to the power n.
And the space complexity of this solution is O of n, because space is used up on the recursion call
stack.
Now again remember in this solution initially we are sorting the array which is an o of n log n time
complexity operation.
But then n into two to the power n is much higher than n log n, and therefore we can ignore this.
So the time complexity is o of n into two to the power n, and the space complexity is O of n.
If we ignore any space that's taken up while sorting the array.