easy +8 pts

Power set size

Count the number of subsets for a list of integers.

Write a function `power_set_size(seq: list[int]) -> int` that returns the total number of distinct subsets that can be formed from the elements in `seq`. For an input list of length `n`, the power set size is `2**n`. The order of elements in `seq` does not affect the count. For an empty list, the power set contains only the empty subset, so return `1`. **Input**: A list of integers, possibly empty. **Output**: An integer representing the number of subsets.

Constraints

0 <= len(seq) <= 60. The result is guaranteed to fit within a Python integer (Python ints are arbitrary precision).

Example

>>> power_set_size([])
1
>>> power_set_size([1, 2])
4
>>> power_set_size([1, 2, 3])
8
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Each element can either be included or excluded from a subset.
With n independent choices, the total number of subsets is 2 raised to the power n.
Use the exponentiation operator ** in Python.
The empty list has exactly one subset: the empty set.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.