💯Faster✅💯 | |unordered set||sorting|| 🔥Python🐍Java☕C++😎
Intuition\n Describe your first thoughts on how to solve this problem. \nSeeking Negatives: Since we\'re looking for pairs of positive and negative integers in 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSeeking Negatives: Since we\'re looking for pairs of positive and negative integers in the array, one way to approach this problem is to iterate through the array and for each positive number, check if its negative counterpart exists in the array.\nTracking Maximum: While traversing the array, we\'ll keep track of the largest positive integer k for which its negative counterpart -k exists in the array.\nUsing a Set: We use a set data structure to efficiently check if a negative counterpart exists for a given positive number. Sets offer constant-time lookup complexity on average, making this operation fast.\nMaximizing k: As we iterate through the array, whenever we find a positive number num for which -num exists in the set, we compare its absolute value with the current maximum k. If num is greater than the current k, we update k to num.\nReturning the Result: After iterating through the entire array, if we\'ve found a valid k, we return it. Otherwise, we return -1 to indicate that no such k exists.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCreate a set: First, create an unordered set to store all the integers in the input array. This allows for quick lookups to check if a certain integer exists in the array.\nIterate through the array: Traverse through the input array, and for each element num, check if its negative counterpart -num exists in the set. If it does, update the largest_k variable with the maximum of its current value and the absolute value of num.\nReturn the result: After iterating through the entire array, check if largest_k has been updated. If it has, return largest_k. Otherwise, return -1, indicating that there is no valid k in the array.\nHandle edge cases: Ensure the input array is not empty. If it is, return -1 as there are no elements to process.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\no(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\no(n)\n\n# Code\n\n# C++\n```\nclass Solution {\npublic:\n    int findMaxK(std::vector<int>& nums) {\n        std::unordered_set<int> num_set(nums.begin(), nums.end());\n        int largest_k = -1;\n\n        for (int num : nums) {\n            if (num_set.find(-num) != num_set.end()) {\n                largest_k = std::max(largest_k, std::abs(num));\n            }\n        }\n\n        return largest_k != -1 ? largest_k : -1;\n    }\n};\n```\n# python\n```\n\nint largest_negative_pair(std::vector<int>& nums) {\n    std::unordered_set<int> num_set(nums.begin(), nums.end());\n    int largest_k = -1;\n\n    for (int num : nums) {\n        if (num_set.find(-num) != num_set.end()) {\n            largest_k = std::max(largest_k, std::abs(num));\n        }\n    }\n\n    return largest_k != -1 ? largest_k : -1;\n}\n\n```\n# java\n```\nimport java.util.HashSet;\n\nclass Solution {\n    public int findMaxK(int[] nums) {\n        HashSet<Integer> numSet = new HashSet<>();\n        int largestK = -1;\n\n        for (int num : nums) {\n            numSet.add(num);\n        }\n\n        for (int num : nums) {\n            if (numSet.contains(-num)) {\n                largestK = Math.max(largestK, Math.abs(num));\n            }\n        }\n\n        return largestK != -1 ? largestK : -1;\n    }\n}\n```
['Array', 'Two Pointers', 'Sorting', 'Ordered Set', 'Python', 'C++', 'Java']