Skip to main content
PreparationZone Logo
PreparationZone
Back to Coding

Coding · Medium · Pro

Generate all subsets (power set) of an array

CodingRecursionBacktrackingSenior
Model answerPreview

Approach

  • At each index, choose to include or exclude the element.
  • Base case: index == length → add current path to result.

Java Solution

Java
public List<List<Integer>> subsets(int[] nums) {
    List<Li…