C++|| Simple Solution with small optimization || Beats 99.24%
\n\n# Approach\n Describe your approach to solving the problem. \nSort the array. \ntake two pointers i and j where i wil keep track of negative numbers and j w
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSort the array. \ntake two pointers i and j where i wil keep track of negative numbers and j will keep track of positive numbers.\nif(nums[i]+nums[j] < 0) that means abs(nums[i]) is > nums[j] so we move i pointer forward.\nif(nums[i]+nums[j] > 0) that means abs(nums[i]) is < nums[j] so we move j pointer forward.\nif sum becomes zero that means -k+k=0 so k will be my answer or nums[j] will be my answer.\n\n**Small optimization:**\nif nums[i] becomes > 0 we return -1 bcoz nums[j] is >0 and nums[i]>0 we cant find the answer in this case.\nSimilarly if nums[j] becomes < 0 we return -1 bcoz nums[i] is < 0.\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int findMaxK(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        if(nums[0]>0 || nums[nums.size()-1] <0) return -1;\n        int i=0,j=nums.size()-1;\n        while(i<j){\n           if(nums[i]+nums[j] == 0) return nums[j];\n           else if((nums[i]+nums[j]) < 0) i++;\n           else j--;\n\n           if(nums[i] >0 || nums[j]<0) break;\n        }\n        return -1;\n    }\n};\n```
['Two Pointers', 'Sorting', 'C++']