79091465

Date: 2024-10-15 19:30:18
Score: 0.5
Natty:
Report link

Given n numbers to choose from, both O(2^n) ad O(n) are correct answers.

It's O(2^n) because you are picking between 2 options (to include or not include) for each of the n numbers and will end up with O(2^n) subsets generated.

But generally, you don't consider space of the result you return because that's just expected cost you must incur no matter what. So at each step of the recursion, you only have the temporary array of max length n that you keep adding and removing numbers from. So max auxiliary space is O(n).

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: piritocle