Dsa
Backtracking
Warm-up
Subset Sums
Given an array of distinct integers, return all possible subsets (the power set). The subsets should be printed in sorted order. Each subset should be on a new line.
Input:
The input consists of a single line containing space-separated integers.
Output:
The output should contain each subset, sorted in ascending order, each on a new line.
Example:
Input:
1 2 3
Output:
1
1 2
1 2 3
1 3
2
2 3
3
Key concepts
backtrackingsubsetsarrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now