{"id":"76686f1e-cc94-494f-9f41-4e47e5c32c6c","name":"2 Sum - Target Sum Unique Pairs","description":"1. Given an Array of size 'n' have may or may not be repeated elements.\r\n2. A 'target' is provided.\r\n3. Return Pair of target sum in which all pairs are unique, for example : [1, 2], [2, 1] are consider as same pair.\r\n4. If array have repeated element then return only unique pair, for example : if array is arr = [2, 2, 4, 4], and target = 6 then res have only one pair, i.e. [2, 4]\r\n","inputFormat":"Input is managed for you.","outputFormat":"Output is managed for you.","constraints":"1. 2 &lt;= n &lt; 10000\r\n2. -10^9 &lt; arr[i] &lt; 10^9\r\n3. pair[0] + pair[1] &lt; 10^9\r\n","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nvector<vector<int>> twoSum(vector<int>& arr, int target)\n{\n //write your code here \n}\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 = twoSum(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 \n finalResult.push_back(ans);\n }\n sort(finalResult.begin(), finalResult.end());\n\n \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 // ~~~~~~~~~~~~User Section~~~~~~~~~~~~\r\n public static List<List<Integer>> twoSum(int[] arr, int target) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~Input Management~~~~~~~~~~\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 = twoSum(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":"easy","sampleInput":"6\r\n10 10 30 40 50 20\r\n60\r\n","sampleOutput":"10 50 \r\n20 40 ","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":"79262db8-317b-4e2b-bc3d-433185c3ad97","name":"2 Sum - Target Sum Unique Pairs","slug":"2-sum-target-sum-unique-pairs","type":1}],"next":{"id":"63fd869b-295c-47e5-831a-041a27dd8615","name":"2 Sum - Target Sum Unique Pairs","type":3,"slug":"2-sum-target-sum-unique-pairs"},"prev":{"id":"a7fda84c-c6b6-4e4e-9a0a-78bdda6e768f","name":"Segmented Sieve MCQ","type":0,"slug":"segmented-sieve-mcq"}}}

2 Sum - Target Sum Unique Pairs

1. Given an Array of size 'n' have may or may not be repeated elements. 2. A 'target' is provided. 3. Return Pair of target sum in which all pairs are unique, for example : [1, 2], [2, 1] are consider as same pair. 4. If array have repeated element then return only unique pair, for example : if array is arr = [2, 2, 4, 4], and target = 6 then res have only one pair, i.e. [2, 4]

{"id":"76686f1e-cc94-494f-9f41-4e47e5c32c6c","name":"2 Sum - Target Sum Unique Pairs","description":"1. Given an Array of size 'n' have may or may not be repeated elements.\r\n2. A 'target' is provided.\r\n3. Return Pair of target sum in which all pairs are unique, for example : [1, 2], [2, 1] are consider as same pair.\r\n4. If array have repeated element then return only unique pair, for example : if array is arr = [2, 2, 4, 4], and target = 6 then res have only one pair, i.e. [2, 4]\r\n","inputFormat":"Input is managed for you.","outputFormat":"Output is managed for you.","constraints":"1. 2 &lt;= n &lt; 10000\r\n2. -10^9 &lt; arr[i] &lt; 10^9\r\n3. pair[0] + pair[1] &lt; 10^9\r\n","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nvector<vector<int>> twoSum(vector<int>& arr, int target)\n{\n //write your code here \n}\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 = twoSum(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 \n finalResult.push_back(ans);\n }\n sort(finalResult.begin(), finalResult.end());\n\n \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 // ~~~~~~~~~~~~User Section~~~~~~~~~~~~\r\n public static List<List<Integer>> twoSum(int[] arr, int target) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~Input Management~~~~~~~~~~\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 = twoSum(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":"easy","sampleInput":"6\r\n10 10 30 40 50 20\r\n60\r\n","sampleOutput":"10 50 \r\n20 40 ","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":"79262db8-317b-4e2b-bc3d-433185c3ad97","name":"2 Sum - Target Sum Unique Pairs","slug":"2-sum-target-sum-unique-pairs","type":1}],"next":{"id":"63fd869b-295c-47e5-831a-041a27dd8615","name":"2 Sum - Target Sum Unique Pairs","type":3,"slug":"2-sum-target-sum-unique-pairs"},"prev":{"id":"a7fda84c-c6b6-4e4e-9a0a-78bdda6e768f","name":"Segmented Sieve MCQ","type":0,"slug":"segmented-sieve-mcq"}}}
plane

Editor


Loading...

2 Sum - Target Sum Unique Pairs

easy

1. Given an Array of size 'n' have may or may not be repeated elements. 2. A 'target' is provided. 3. Return Pair of target sum in which all pairs are unique, for example : [1, 2], [2, 1] are consider as same pair. 4. If array have repeated element then return only unique pair, for example : if array is arr = [2, 2, 4, 4], and target = 6 then res have only one pair, i.e. [2, 4]

Constraints

1. 2 <= n < 10000 2. -10^9 < arr[i] < 10^9 3. pair[0] + pair[1] < 10^9

Format

Input

Input is managed for you.

Output

Output is managed for you.

Example

Sample Input

6 10 10 30 40 50 20 60

Sample Output

10 50 20 40

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode