{"id":"e1020368-59dc-41e6-a5df-0d9d12c72f21","name":"K Sum - Target Sum Unique Set","description":"1. Given an array nums of 'n' integers and a variable 'K'.\r\n2. You have to return an array of all the unique set [nums[a], nums[b], nums[c], nums[d] . . . K Elements] such that: \r\n 2.1 a, b, c, d . . . K Elements are less than 'n' and greater than 0.\r\n 2.2 a,. b, c, d upto K different indexes are Unique.\r\n 2.3 nums[a] + nums[b] + nums[c] + nums[d] + . . . + nums[K distinct indexes] == target.\r\n3. You can return answer in any order.\r\n","inputFormat":"Input is managed for you.\r\n","outputFormat":"Output is managed for you.","constraints":"1. 1 &lt;= nums.length &lt;= 200\r\n2. -10^9 &lt;= nums[i] &lt;= 10^9\r\n3. -10^9 &lt;= target &lt;= 10^9\r\n4. 1 &lt;= K &lt;= nums.length\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvector<vector<int>> kSum(vector<int> &arr, int target, int k) {\n //write your code here\n}\n\nint main(){\n int n, target, k;\n cin>>n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n cin>>target>>k;\n \n vector<vector<int>> res=kSum(arr, target, k);\n vector<string> finalResult;\n \n for (vector<int> list : res) {\n sort(list.begin(), list.end());\n string ans = \"\";\n for (int val : list) {\n ans += to_string(val) + \" \";\n }\n finalResult.push_back(ans);\n }\n sort(finalResult.begin(), finalResult.end());\n for (string str : finalResult) {\n cout<<str<<endl;\n }\n }"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static List<List<Integer>> kSum(int[] arr, int target, int k) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n int target = scn.nextInt();\r\n int k = scn.nextInt();\r\n List<List<Integer>> res = kSum(arr, target, k);\r\n ArrayList<String> finalResult = new ArrayList<>();\r\n for (List<Integer> list : res) {\r\n Collections.sort(list);\r\n String ans = \"\";\r\n for (int val : list) {\r\n ans += val + \" \";\r\n }\r\n finalResult.add(ans);\r\n }\r\n Collections.sort(finalResult);\r\n for (String str : finalResult) {\r\n System.out.println(str);\r\n }\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"6\r\n-1 0 1 2 -1 -4\r\n0\r\n3","sampleOutput":"-1 -1 2 \r\n-1 0 1 ","questionVideo":"","hints":[],"associated":[],"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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"7226b20d-cfa6-4013-8783-89a74cc07d88","name":"K Sum - Target Sum Unique Set","slug":"k-sum-target-sum-unique-set","type":1}],"next":{"id":"06a775a0-e2a1-45d5-ac76-f20fa8695ebb","name":"K Sum - Target Sum Unique Set","type":3,"slug":"k-sum-target-sum-unique-set"},"prev":{"id":"2b2835cb-c8e2-4a4f-b37e-29e530dc8639","name":"Smallest Range Covering Elements From K Lists MCQ","type":0,"slug":"smallest-range-covering-elements-from-k-lists-mcq"}}}

K Sum - Target Sum Unique Set

1. Given an array nums of 'n' integers and a variable 'K'. 2. You have to return an array of all the unique set [nums[a], nums[b], nums[c], nums[d] . . . K Elements] such that: 2.1 a, b, c, d . . . K Elements are less than 'n' and greater than 0. 2.2 a,. b, c, d upto K different indexes are Unique. 2.3 nums[a] + nums[b] + nums[c] + nums[d] + . . . + nums[K distinct indexes] == target. 3. You can return answer in any order.

{"id":"e1020368-59dc-41e6-a5df-0d9d12c72f21","name":"K Sum - Target Sum Unique Set","description":"1. Given an array nums of 'n' integers and a variable 'K'.\r\n2. You have to return an array of all the unique set [nums[a], nums[b], nums[c], nums[d] . . . K Elements] such that: \r\n 2.1 a, b, c, d . . . K Elements are less than 'n' and greater than 0.\r\n 2.2 a,. b, c, d upto K different indexes are Unique.\r\n 2.3 nums[a] + nums[b] + nums[c] + nums[d] + . . . + nums[K distinct indexes] == target.\r\n3. You can return answer in any order.\r\n","inputFormat":"Input is managed for you.\r\n","outputFormat":"Output is managed for you.","constraints":"1. 1 &lt;= nums.length &lt;= 200\r\n2. -10^9 &lt;= nums[i] &lt;= 10^9\r\n3. -10^9 &lt;= target &lt;= 10^9\r\n4. 1 &lt;= K &lt;= nums.length\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvector<vector<int>> kSum(vector<int> &arr, int target, int k) {\n //write your code here\n}\n\nint main(){\n int n, target, k;\n cin>>n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n cin>>target>>k;\n \n vector<vector<int>> res=kSum(arr, target, k);\n vector<string> finalResult;\n \n for (vector<int> list : res) {\n sort(list.begin(), list.end());\n string ans = \"\";\n for (int val : list) {\n ans += to_string(val) + \" \";\n }\n finalResult.push_back(ans);\n }\n sort(finalResult.begin(), finalResult.end());\n for (string str : finalResult) {\n cout<<str<<endl;\n }\n }"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static List<List<Integer>> kSum(int[] arr, int target, int k) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n int target = scn.nextInt();\r\n int k = scn.nextInt();\r\n List<List<Integer>> res = kSum(arr, target, k);\r\n ArrayList<String> finalResult = new ArrayList<>();\r\n for (List<Integer> list : res) {\r\n Collections.sort(list);\r\n String ans = \"\";\r\n for (int val : list) {\r\n ans += val + \" \";\r\n }\r\n finalResult.add(ans);\r\n }\r\n Collections.sort(finalResult);\r\n for (String str : finalResult) {\r\n System.out.println(str);\r\n }\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"6\r\n-1 0 1 2 -1 -4\r\n0\r\n3","sampleOutput":"-1 -1 2 \r\n-1 0 1 ","questionVideo":"","hints":[],"associated":[],"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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"7226b20d-cfa6-4013-8783-89a74cc07d88","name":"K Sum - Target Sum Unique Set","slug":"k-sum-target-sum-unique-set","type":1}],"next":{"id":"06a775a0-e2a1-45d5-ac76-f20fa8695ebb","name":"K Sum - Target Sum Unique Set","type":3,"slug":"k-sum-target-sum-unique-set"},"prev":{"id":"2b2835cb-c8e2-4a4f-b37e-29e530dc8639","name":"Smallest Range Covering Elements From K Lists MCQ","type":0,"slug":"smallest-range-covering-elements-from-k-lists-mcq"}}}
plane

Editor


Loading...

K Sum - Target Sum Unique Set

hard

1. Given an array nums of 'n' integers and a variable 'K'. 2. You have to return an array of all the unique set [nums[a], nums[b], nums[c], nums[d] . . . K Elements] such that: 2.1 a, b, c, d . . . K Elements are less than 'n' and greater than 0. 2.2 a,. b, c, d upto K different indexes are Unique. 2.3 nums[a] + nums[b] + nums[c] + nums[d] + . . . + nums[K distinct indexes] == target. 3. You can return answer in any order.

Constraints

1. 1 <= nums.length <= 200 2. -10^9 <= nums[i] <= 10^9 3. -10^9 <= target <= 10^9 4. 1 <= K <= nums.length

Format

Input

Input is managed for you.

Output

Output is managed for you.

Example

Sample Input

6 -1 0 1 2 -1 -4 0 3

Sample Output

-1 -1 2 -1 0 1

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode