👏Best Java Solution🎉 || ⏩Fastest🤯 ||✅Simple & Easy Well Explained Approach🔥💥
Intuition\nThe problem aims to find the maximum absolute value among pairs of numbers where one is the negative of the other, given an array of integers. It uti
# Intuition\nThe problem aims to find the maximum absolute value among pairs of numbers where one is the negative of the other, given an array of integers. It utilizes HashSet for efficient lookup of negative counterparts.\n\n# I Think This Can Help You(For Proof Click on the Image)\n[![Screenshot 2024-02-24 232407.png](https://assets.leetcode.com/users/images/8e502460-a001-4013-beb4-cef8252da000_1714619726.0656989.png)](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/submissions/1247032507/?envType=daily-question&envId=2024-05-02)\n\n# Approach\n1. **HashSet Initialization**:\n   ```java\n   HashSet<Integer> hs = new HashSet<>();\n   ```\n   This line initializes a HashSet named `hs` to store integer values. HashSet is used because it provides constant-time average complexity for basic operations like add and contains.\n\n2. **Iterating Through the Array**:\n   ```java\n   for (int num : nums) {\n       // Loop body\n   }\n   ```\n   This loop iterates over each element `num` in the input array `nums`.\n\n3. **Adding Elements to HashSet**:\n   ```java\n   hs.add(num);\n   ```\n   Inside the loop, each encountered number `num` is added to the HashSet `hs`.\n\n4. **Calculating Negative of the Number**:\n   ```java\n   int k = num * (-1);\n   ```\n   This line calculates the negative of the current number `num` and stores it in variable `k`.\n\n5. **Checking for Negative Counterpart**:\n   ```java\n   if (hs.contains(k)) {\n       // Code block\n   }\n   ```\n   It checks if the HashSet `hs` contains the negative counterpart `k` of the current number `num`. If it does, it means there\'s a pair with one number being the negative of the other.\n\n6. **Updating Maximum Absolute Value**:\n   ```java\n   ans = Math.max(ans, Math.abs(num));\n   ```\n   If a pair is found, it updates the `ans` variable with the maximum absolute value among the current number `num` and the current value of `ans`.\n\n7. **Returning the Maximum Absolute Value**:\n   ```java\n   return ans;\n   ```\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```java\nclass Solution {\n    public int findMaxK(int[] nums) {\n        HashSet<Integer> hs = new HashSet<>();\n        int ans = -1;\n        for(int num : nums){\n            hs.add(num);\n            int k = num*(-1);\n            if(hs.contains(k)){\n                ans = Math.max(ans,Math.abs(num));\n            }\n        }\n        return ans;\n    }\n}\n```\n\n![_a0e33399-39b7-476a-994b-e8aaac97926c.jpeg](https://assets.leetcode.com/users/images/973cb0ff-dd7a-4454-8aab-7b5b89a74a2b_1714709826.2688804.jpeg)\n
['Array', 'Hash Table', 'Two Pointers', 'Sorting', 'Java']