✅beats👊99% 💯Faster✅ Detailed Explanation
Intuition:\n# Given an array of integers, we need to find the maximum positive integer num such that its negation -num also exists in the array.\n# Approach:\n1
# Intuition:\n# **Given an array of integers, we need to find the maximum positive integer num such that its negation -num also exists in the array.**\n# Approach:\n1. **Create a set s containing all elements of the input array nums.**\n2. **Initialize a variable pair to -1, which will store the maximum positive integer that has a negation in the set.**\n3. **Iterate through each element num in the array nums.**\n4. **Check if num is positive and its negation -num exists in the set s.**\n5. **If both conditions are true, update pair to the maximum of its current value and num.**\n6. **Return the value of pair, which represents the maximum positive integer having its negation in the array.**\n# Complexity:\n- **Time complexity**:\nO(n)\n- **Space complexity**:\nO(n)\n# Code\n```Python []\nclass Solution:\n    def findMaxK(self, nums: List[int]) -> int:\n        s = set(nums)\n\n        pair = -1\n        for num in nums:\n            if num > 0 and -num in s:\n                pair = max(pair, num)\n        return pair\n```\n```C++ []\nint findMaxK(vector<int>& nums) {\n    unordered_set<int> s(nums.begin(), nums.end());\n    int pair = -1;\n    for (int num : nums) {\n        if (num > 0 && s.count(-num)) {\n            pair = max(pair, num);\n        }\n    }\n    return pair;\n```\n```Java []\nclass Solution {\n    public int findMaxK(int[] nums) {\n        HashSet<Integer> set = new HashSet<>();\n        for (int num : nums) {\n            set.add(num);\n        }\n        int pair = -1;\n        for (int num : nums) {\n            if (num > 0 && set.contains(-num)) {\n                pair = Math.max(pair, num);\n            }\n        }\n        return pair;\n    }\n}\n```\n
['Array', 'Hash Table', 'Two Pointers', 'Sorting', 'C++', 'Java', 'Python3']