FreeCareerPath
Build the PrimitiveMedium

Subsets

Write `subsets(nums)` returning every subset of a list of distinct integers. Order does not matter, but no subset may repeat. subsets([1,2,3]) -> 8 subsets, including [] and [1,2,3] At each index you either take the element or you do not, which is exactly why there are 2^n results. Append a *copy* of the current selection — appending the working list itself gives you n identical empty lists at the end.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Subsets" are saved to your account — logging in takes a few seconds.

Subsets — FreeCareerPath