educative.io

More succinct solution

def find_subsets(nums):
  subsets = [[]]
  for num in nums:
    subsets += [x + [num] for x in subsets]
  return subsets

Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/5670249378611200

It’s a good solution but your solution solves the problem in O(N^2).

That would be better than O(N∗2​^N​​), right?
But I think the complexity is the same as in the proposed solution: “for x in subsets” loops 2^N times as “n = len(subsets); for i in range(n)” in the proposed solution.

1 Like