{"id":"62b7e7de-7ace-41d9-a1c1-a1f02710d7f3","name":"Subsets Of Array","description":"1. You are given a number n, representing the count of elements.\r\n2. You are given n numbers.\r\n3. You are required to print all subsets of arr. Each subset should be\r\non separate line. For more clarity check out sample input and output.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"[Tab separated elements of subset]\r\n..\r\nAll subsets","constraints":"1 &lt;= n &lt;= 10\r\n0 &lt;= n1, n2, .. n elements &lt;= 10^3","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n int n;\r\n cin>>n;\r\n\r\n vector<int> arr(n);\r\n\r\n for(int i =0;i<n;i++)\r\n {\r\n cin>>arr[i];\r\n }\r\n\r\n printSubsets(arr);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n \r\n int n = Integer.parseInt(br.readLine());\r\n int[] arr = new int[n];\r\n for(int i = 0; i < n; i++){\r\n arr[i] = Integer.parseInt(br.readLine());\r\n }\r\n\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printSubsets(lists):\r\n # write your code here\r\n \r\n \r\n\r\n\r\nn = int(input())\r\n\r\nlists = []\r\n\r\nfor i in range(0,n):\r\n ele = int(input())\r\n lists.append(ele)\r\n\r\nprintSubsets(lists)"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n10\r\n20\r\n30","sampleOutput":"-\t-\t-\t\r\n-\t-\t30\t\r\n-\t20\t-\t\r\n-\t20\t30\t\r\n10\t-\t-\t\r\n10\t-\t30\t\r\n10\t20\t-\t\r\n10\t20\t30","questionVideo":"https://www.youtube.com/embed/vk8sfizNtsY","hints":[],"associated":[{"id":"006f574b-212d-4026-8489-0bd04dd042a3","name":"(Subsets of array) Space complexity of this question.","slug":"subsets-of-array-space-complexity-of-this-question","type":4},{"id":"34425ae8-6cb9-46d1-a565-8808eb826b0e","name":"(Subsets of array) For n no. of element how many subsets are possible?","slug":"subsets-of-array-for-n-no-of-element-how-many-subsets-are-possible","type":4},{"id":"34f6bab4-3210-4eab-a243-79e60dfac65a","name":"(Subsets of array) Time complexity to solve this question","slug":"subsets-of-array-time-complexity-to-solve-this-question","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"7eddf43f-059b-45c7-91a1-e4a0e1dcbfa7","name":"Subsets Of Array","slug":"subsets-of-array","type":1}],"next":{"id":"dad75206-58e0-4066-b48c-a478d148a7fa","name":"Subsets of Array","type":3,"slug":"subsets-of-array"},"prev":{"id":"04d40c08-6f5b-4e5e-9f51-c65f2ffd379b","name":"Sub Arrays Of An Array","type":3,"slug":"sub-arrays-of-an-array"}}}

Subsets Of Array

1. You are given a number n, representing the count of elements. 2. You are given n numbers. 3. You are required to print all subsets of arr. Each subset should be on separate line. For more clarity check out sample input and output.

{"id":"62b7e7de-7ace-41d9-a1c1-a1f02710d7f3","name":"Subsets Of Array","description":"1. You are given a number n, representing the count of elements.\r\n2. You are given n numbers.\r\n3. You are required to print all subsets of arr. Each subset should be\r\non separate line. For more clarity check out sample input and output.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"[Tab separated elements of subset]\r\n..\r\nAll subsets","constraints":"1 &lt;= n &lt;= 10\r\n0 &lt;= n1, n2, .. n elements &lt;= 10^3","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n int n;\r\n cin>>n;\r\n\r\n vector<int> arr(n);\r\n\r\n for(int i =0;i<n;i++)\r\n {\r\n cin>>arr[i];\r\n }\r\n\r\n printSubsets(arr);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n \r\n int n = Integer.parseInt(br.readLine());\r\n int[] arr = new int[n];\r\n for(int i = 0; i < n; i++){\r\n arr[i] = Integer.parseInt(br.readLine());\r\n }\r\n\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printSubsets(lists):\r\n # write your code here\r\n \r\n \r\n\r\n\r\nn = int(input())\r\n\r\nlists = []\r\n\r\nfor i in range(0,n):\r\n ele = int(input())\r\n lists.append(ele)\r\n\r\nprintSubsets(lists)"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n10\r\n20\r\n30","sampleOutput":"-\t-\t-\t\r\n-\t-\t30\t\r\n-\t20\t-\t\r\n-\t20\t30\t\r\n10\t-\t-\t\r\n10\t-\t30\t\r\n10\t20\t-\t\r\n10\t20\t30","questionVideo":"https://www.youtube.com/embed/vk8sfizNtsY","hints":[],"associated":[{"id":"006f574b-212d-4026-8489-0bd04dd042a3","name":"(Subsets of array) Space complexity of this question.","slug":"subsets-of-array-space-complexity-of-this-question","type":4},{"id":"34425ae8-6cb9-46d1-a565-8808eb826b0e","name":"(Subsets of array) For n no. of element how many subsets are possible?","slug":"subsets-of-array-for-n-no-of-element-how-many-subsets-are-possible","type":4},{"id":"34f6bab4-3210-4eab-a243-79e60dfac65a","name":"(Subsets of array) Time complexity to solve this question","slug":"subsets-of-array-time-complexity-to-solve-this-question","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"7eddf43f-059b-45c7-91a1-e4a0e1dcbfa7","name":"Subsets Of Array","slug":"subsets-of-array","type":1}],"next":{"id":"dad75206-58e0-4066-b48c-a478d148a7fa","name":"Subsets of Array","type":3,"slug":"subsets-of-array"},"prev":{"id":"04d40c08-6f5b-4e5e-9f51-c65f2ffd379b","name":"Sub Arrays Of An Array","type":3,"slug":"sub-arrays-of-an-array"}}}
plane

Editor


Loading...

Subsets Of Array

easy

1. You are given a number n, representing the count of elements. 2. You are given n numbers. 3. You are required to print all subsets of arr. Each subset should be on separate line. For more clarity check out sample input and output.

Constraints

1 <= n <= 10 0 <= n1, n2, .. n elements <= 10^3

Format

Input

A number n n1 n2 .. n number of elements

Output

[Tab separated elements of subset] .. All subsets

Example

Sample Input

3 10 20 30

Sample Output

- - - - - 30 - 20 - - 20 30 10 - - 10 - 30 10 20 - 10 20 30

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode