Subsets Flashcards

(5 cards)

1
Q

What is the definition of Subsets?

A

Generates all possible subsets of a set.

Use Case: Combinatorial problems, power set.

Example: [No LeetCode match, course example: Subsets].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the key steps for Subsets?

A
  1. Start with empty subset.
  2. For each element, create new subsets by adding it.
  3. Return all subsets.

Action: Explain steps for Subsets aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does it apply to Subsets?

A

Problem: Generate all subsets of a set.
Approach: Iteratively add each element to existing subsets.

Example: Subsets. Action: Verbalize solution logic aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the complexity and gotchas of Subsets?

A

Complexity: Time: O(2^n), Space: O(2^n).
Gotchas: Empty set, duplicate elements.

Action: List edge cases for Subsets aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Code example for Subsets.

A

```python
from typing import List
def subsets(nums: List[int]) -> List[List[int]]:
result: List[List[int]] = [[]]
for num in nums:
result += [subset + [num] for subset in result]
return result
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly