Generate Subsets

Advanced

Welcome to the Subset Generator!

In this challenge, you're going to create a function that generates all possible subsets of a given list of numbers. A subset is a list that contains elements that may or may not be in their original order but without any repetition from the original list.

Imagine you have a magic bag of marbles, where each marble has a number on it. You want to see all different ways you can take some or none of these marbles out. This means, you will create every possible combination of marbles you can select, including the scenario where you don't take any!

To be exact, your task is to write a function generate_subsets that takes in a list of unique numbers and returns a list of all possible subsets of this list.

For example:

generate_subsets([1, 2])

Should return:

[[], [1], [2], [1, 2]]

And another example:

generate_subsets([1, 2, 3])

Should return:

[[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]

Key Points to Remember:

  • The list does not have duplicated numbers.
  • The empty set is always part of the subsets.
  • The order of subsets or the numbers within them doesn't really matter in the result.

Now, let your creativity flow and start generating those magical subsets!

Geek
Inputs

Arg 1:

[1,2]
Expected Output
[[], [1], [2], [1, 2]]
Actual Output