Two Pointer_Very simple_Python_C++
Intuition\n\npython []\nclass Solution:\n    def findMaxK(self, nums: List[int]) -> int:\n        nums.sort()\n        l, r = 0, len(nums)-1\n        \n        
# Intuition\n\n```python []\nclass Solution:\n    def findMaxK(self, nums: List[int]) -> int:\n        nums.sort()\n        l, r = 0, len(nums)-1\n        \n        while(nums[l]<0 and l<r):\n            if nums[l]*(-1) == nums[r]:\n                return nums[r]\n            if nums[l]*(-1) > nums[r]:\n                l += 1\n            else:\n                r -= 1\n        \n        return -1\n```\n```C++ []\nclass Solution {\npublic:\n    int findMaxK(vector<int>& nums) {\n        int i=0;\n        sort(nums.begin(), nums.end());\n\n        int r = nums.size()-1;\n        int l = 0;\n        while(nums[l] < 0 && l<r){\n            if(nums[l] == -nums[r])\n                return nums[r];\n            if(-nums[l] > nums[r])\n                l++;\n            else\n                r--;\n        }\n        return -1;\n    }\n};\n```\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nLet\'s understand with an example, \nnums = [-1, -2, -10, 3, 4, 2, 7]\nafter sorting the array,\nnums = [-10, -2, -1, 2, 3, 4, 7]\nfixed the left and right pointer :: left = 0, right = nums.size()-1\nnow iterate for left and right while(left < right)\n\nnums[left] = nums[0] = -10\nnums[right] = nums[6] = 7\nnums[left]*(-1) = -10*(-1) = 10\n**10 > 7** so make the **left++** [move the left pointer forward] cause it is not possible having the element 10 inside the array\n\nnow left = 1 and right remain same, right = 6\nnums[left]*(-1) = nums[1]*(-1) = 2\nnums[right] = nums[6] = 7\n**2 < 7** so make the **right--** [move the right pointer backward cause it is not possible having the element -7 inside the array]\n\nnow left remain same and right = 5 and so on.\nin this way the right will stop at the point 3\nthen, \n**nums[left] = nums[1] = -2\nnums[right] = nums[3] = 2\nnow nums[1]*-1 == nums[3]\n    so return nums[3];**\n\n\nafter iterating while(left < right)\n    if we don\'t get any same value like nums[left]*(-1) == nums[right]\nthen it is proved that there is no element exist like that.\nso **return -1**.\n\n\n\n# Complexity\n- Time complexity:\nO(n)\n\n\n# Please upvote it, if this solution has helped you at all.  \n\n\n\n\n\n\n\n\n\n\n\n
['Two Pointers', 'C++', 'Python3']