✅Variation of TWO SUM Problem||Two approaches
First Approach\n#### This problem is similar to Two sum problem \n\nTwo Sum Problem :-  finding two elements that make up a sum k\nThis problem :- the value of 
### First Approach\n#### This problem is similar to Two sum problem \n\n`Two Sum Problem :-  finding two elements that make up a sum k`\n`This problem :- the value of k is zero that is sum we need to find is 0 and then if there are multiple of them return the max`\n\nSo simply we need to find its additive inverse \n\n```c++\n#include<bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n    int findMaxK(vector<int>& nums) {\n\t\t// keep track of maximum\n        int maxi = INT_MIN;\n\t\t// set to remeber the other value \n        unordered_set<int> s;\n        for(auto i : nums){\n            if(s.find(i * -1) == s.end()){\n\t\t\t\t// if not found insert\n                s.insert(i);\n            }else{\n\t\t\t\t// if found update maxi \n                maxi = max(maxi, abs(i));\n            }\n        }\n\t\t// if not present return -1 else return maxi\n        return maxi == INT_MIN ? -1 : maxi;\n    }\n};\n//  time complexiy O(n) \n// space complexity O(n)\n```\n### Second Approach \n\n* sort the numbers then using two pointers solve the problem\n\n```c++\nclass Solution {\npublic:\n    int findMaxK(vector<int>& nums) {\n\t\t// sort the numbers O(nlogn)\n        sort(nums.begin(), nums.end());\n        int l = 0, h = nums.size() - 1;\n        while(l < h){\n            int sum = nums[l] + nums[h];\n\t\t\t// if sum is zero we have found our answer\n            if(sum == 0)\n                return nums[h];\n\t\t\t// if sum is positive then we need to push right pointer to reduce the positiveness \n            else if(sum > 0){\n                h--;\n            }else{\n                l++;\n            }\n        }\n\t\t// If not found\n        return -1;\n    }\n};\n// Time complexity: O(nlogn)\n// Space complexity O(1)\n// IDK Why but this one is faster than the O(n) solution\n```\n##### Edit:- \n\n* The reason Why the first approach is little bit slower is because unordered_map does some internal hashing which also costs some time \n* But as the value of n keeps on increasing O(n) << O(nlogn) i.e time for computing Hash would be significantly lower than sorting\n\n[dvsip](https://leetcode.com/dvisp/) Thank you for pointing this out.
['Array', 'C', 'Sorting']