TCS OA-6 2024
Problem Description
Given an array of integers, nums
, print all possible combinations of the elements in nums
. Each combination should include any subset of elements, from the empty set to the entire array.
Input Format
- The first line contains an integer N, representing the length of the array.
- The second line contains N space-separated integers.
Output Format
Print all the combinations of the array nums.
Constraints
- 1 ≤ N ≤ 100
- 1 ≤ nums[i] ≤ 10³
Example
Sample Input:
4
[1,2,3,4]
Sample Output:
[]
[1]
[2]
[3]
[4]
[1, 2]
[1, 3]
[1, 4]
[2, 3]
[2, 4]
[3, 4]
[1, 2, 3]
[1, 2, 4]
[1, 3, 4]
[2, 3, 4]
[1, 2, 3, 4]
Explanation:
To generate all possible combinations (or subsets) of the array [1, 2, 3, 4]
, we can list each subset. For an array of size n, there are 2ⁿ possible combinations, including the empty subset, which are listed in output.