Beats 98% || you wouldn't have thought of this I BET!!
Intuition\n Describe your first thoughts on how to solve this problem. \n# HEY GUYS WRITING THIS POST TAKES LOT OF EFFORTS , AN UPVOTE WOULD CHEER ME UP FRIEND.
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n# HEY GUYS WRITING THIS POST TAKES LOT OF EFFORTS , AN UPVOTE WOULD CHEER ME UP FRIEND. ALSO GET MY LINKEDIN IN COMMENTS.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n1. **Initializing Variables:**\n   - `int[] positive = new int[1001]`: Creates an integer array `positive` of size 1001. This array will be used to store the frequency of positive numbers encountered in the `nums` array (assuming all positive numbers are less than 1001).\n   - `int[] negative = new int[1001]`: Creates an integer array `negative` of size 1001. This array will be used to store the frequency of negative numbers encountered in the `nums` array (assuming all negative numbers are greater than -1000).\n   - `int ans = -1`: Initializes a variable `ans` to store the maximum absolute difference found so far (similar to the previous solution).\n\n2. **Iterating Through the Array:**\n   - The `for` loop iterates through each element (`nums[i]`) in the `nums` array.\n\n3. **Handling Positive and Negative Numbers:**\n   - The code uses an `if-else` statement to categorize the current element (`nums[i]`).\n     - `if (nums[i] > 0)`: Checks if the element is positive.\n       - `positive[nums[i]]++`: If positive, increments the frequency count for that specific positive number in the `positive` array.\n       - `if (negative[nums[i]] > 0)`: Checks if the negative counterpart of the current element (which would be `-nums[i]`) already has entries in the `negative` array (meaning it has been seen before).\n         - If `negative[nums[i]] > 0`, it means a potential absolute difference exists. The maximum absolute difference (`ans`) is updated using `Math.max(ans, nums[i])`. Here, `nums[i]` itself represents the absolute difference because the negative counterpart has already been seen.\n     - `else`: If the element is not positive, it\'s treated as negative.\n       - `negative[Math.abs(nums[i])]++`: Increments the frequency count for the absolute value (negative counterpart) of the current element in the `negative` array.\n       - `if (positive[Math.abs(nums[i])] > 0)`: Checks if the positive counterpart of the current element (which would be `Math.abs(nums[i])`) already has entries in the `positive` array (meaning it has been seen before).\n         - If `positive[Math.abs(nums[i])] > 0`, it means a potential absolute difference exists. The maximum absolute difference (`ans`) is updated using `Math.max(ans, -nums[i])`. Here, `-nums[i]` represents the absolute difference because the positive counterpart has already been seen.\n\n4. **Returning the Result:**\n   - `return ans`: After iterating through the entire array, `ans` will hold the maximum absolute difference found so far (or -1 if no such difference exists). The code returns this value.\n\n\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- This approach has a time complexity of O(n) due to the single iteration through the array and the constant-time array lookups (assuming the value range is limited).\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\n    public int findMaxK(int[] nums) {\n        int [] positive=new int [1001];\n        int [] negative=new int [1001];\n        int ans=-1;\n        for(int i=0;i<nums.length;i++){\n            if(nums[i]>0){\n                positive[nums[i]]++;\n                if(negative[nums[i]]>0){\n                    ans=Math.max(ans,nums[i]);\n                }\n            }\n            else{\n                negative[Math.abs(nums[i])]++;\n                if(positive[Math.abs(nums[i])]>0){\n                    ans=Math.max(ans,-nums[i]);\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Array', 'Java']