{"id":"7640d2ff-2c01-4b81-9925-bdb1de02f6b4","name":"4 Sum - Target Sum With Unique Quadruple","description":"1. Given an array nums of 'n' integers.\r\n2. You have to return an array of all the unique quadruple [nums[a], nums[b], nums[c], nums[d]] such that: \r\n 2.1 a, b, c, and d are less than 'n' and greater than 0\r\n 2.2 a,. b, c, and d are Unique.\r\n 2.3 nums[a] + nums[b] + nums[c] + nums[d] == 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\n","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n#include <string>\n#include <algorithm>\nusing namespace std;\n\nvector<vector<int>> fourSum(vector<int>& nums, int target) {\n // write your code here\n}\n\nint main() {\n int n = 0;\n cin >> n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin >> arr[i];\n }\n int target = 0;\n cin >> target;\n vector<vector<int>> res = fourSum(arr, target);\n vector<string> finalResult;\n for (int i = 0; i < res.size(); i++) {\n vector<int> list = res[i];\n sort(list.begin(), list.end());\n string ans = \"\";\n for (int i = 0; i < list.size(); i++) {\n int val = list[i];\n ans += to_string(val) ;\n ans+=\" \";\n }\n finalResult.push_back(ans);\n }\n sort(finalResult.begin(), finalResult.end());\n int t=finalResult.size();\n for (int i=0;i<finalResult.size();i++){\n cout<<finalResult[i]<<endl;\n }\n\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static List<List<Integer>> fourSum(int[] nums, int target) {\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 List<List<Integer>> res = fourSum(arr, target);\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}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n1 0 -1 0 -2 2\r\n0","sampleOutput":"-1 0 0 1 \r\n-2 -1 1 2 \r\n-2 0 0 2 ","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":"0939905b-90bc-4006-8bad-7053e2190bfe","name":"4 Sum - Target Sum With Unique Quadruple","slug":"4-sum-target-sum-with-unique-quadruple","type":1}],"next":{"id":"0acf62df-24d3-42e5-bc8e-712d17c4d4f4","name":"4 sum- Target sum with unique Quadruple","type":3,"slug":"4-sum-target-sum-with-unique-quadruple"},"prev":{"id":"7f4f40b6-6180-4a7f-aa9f-11f4dac80b4b","name":"Minimum Domino Rotations For Equal Row MCQ","type":0,"slug":"minimum-domino-rotations-for-equal-row-mcq"}}}

4 Sum - Target Sum With Unique Quadruple

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

{"id":"7640d2ff-2c01-4b81-9925-bdb1de02f6b4","name":"4 Sum - Target Sum With Unique Quadruple","description":"1. Given an array nums of 'n' integers.\r\n2. You have to return an array of all the unique quadruple [nums[a], nums[b], nums[c], nums[d]] such that: \r\n 2.1 a, b, c, and d are less than 'n' and greater than 0\r\n 2.2 a,. b, c, and d are Unique.\r\n 2.3 nums[a] + nums[b] + nums[c] + nums[d] == 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\n","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n#include <string>\n#include <algorithm>\nusing namespace std;\n\nvector<vector<int>> fourSum(vector<int>& nums, int target) {\n // write your code here\n}\n\nint main() {\n int n = 0;\n cin >> n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin >> arr[i];\n }\n int target = 0;\n cin >> target;\n vector<vector<int>> res = fourSum(arr, target);\n vector<string> finalResult;\n for (int i = 0; i < res.size(); i++) {\n vector<int> list = res[i];\n sort(list.begin(), list.end());\n string ans = \"\";\n for (int i = 0; i < list.size(); i++) {\n int val = list[i];\n ans += to_string(val) ;\n ans+=\" \";\n }\n finalResult.push_back(ans);\n }\n sort(finalResult.begin(), finalResult.end());\n int t=finalResult.size();\n for (int i=0;i<finalResult.size();i++){\n cout<<finalResult[i]<<endl;\n }\n\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static List<List<Integer>> fourSum(int[] nums, int target) {\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 List<List<Integer>> res = fourSum(arr, target);\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}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n1 0 -1 0 -2 2\r\n0","sampleOutput":"-1 0 0 1 \r\n-2 -1 1 2 \r\n-2 0 0 2 ","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":"0939905b-90bc-4006-8bad-7053e2190bfe","name":"4 Sum - Target Sum With Unique Quadruple","slug":"4-sum-target-sum-with-unique-quadruple","type":1}],"next":{"id":"0acf62df-24d3-42e5-bc8e-712d17c4d4f4","name":"4 sum- Target sum with unique Quadruple","type":3,"slug":"4-sum-target-sum-with-unique-quadruple"},"prev":{"id":"7f4f40b6-6180-4a7f-aa9f-11f4dac80b4b","name":"Minimum Domino Rotations For Equal Row MCQ","type":0,"slug":"minimum-domino-rotations-for-equal-row-mcq"}}}
plane

Editor


Loading...

4 Sum - Target Sum With Unique Quadruple

medium

1. Given an array nums of 'n' integers. 2. You have to return an array of all the unique quadruple [nums[a], nums[b], nums[c], nums[d]] such that: 2.1 a, b, c, and d are less than 'n' and greater than 0 2.2 a,. b, c, and d are Unique. 2.3 nums[a] + nums[b] + nums[c] + nums[d] == 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

Format

Input

Input is managed for you.

Output

Output is managed for you.

Example

Sample Input

6 1 0 -1 0 -2 2 0

Sample Output

-1 0 0 1 -2 -1 1 2 -2 0 0 2

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode