Maximum Absolute Value Pair in Sorted Array: Two Pointer Approach
Intuition\n The problem likely involves finding some maximum value or satisfying certain conditions within an array. The use of sorting and two pointers suggest
# Intuition\n The problem likely involves finding some maximum value or satisfying certain conditions within an array. The use of sorting and two pointers suggests there\'s a strategy involving comparing elements from both ends of the array.\n\n# Approach\nOne potential approach is to sort the array and then use two pointers, one starting from the beginning and the other from the end. By comparing the absolute values of elements at these pointers, we can gradually move towards the middle, adjusting the pointers based on the comparison.\n\n# Complexity\n- Time complexity:\n Sorting the array takes $$O(n \\log n)$$ time, where $$n$$ is the size of the array. The while loop iterates through the array once, which takes $$O(n)$$ time. Therefore, the overall time complexity is $$O(n \\log n)$$.\n\n- Space complexity:\n The space complexity is $$O(1)$$ since the algorithm uses only a constant amount of extra space, independent of the size of the input array. \n\n# Code\n```\nclass Solution {\npublic:\n    int findMaxK(vector<int>& v) {\n        sort(v.begin(),v.end());\n        int i = 0;\n        int j = v.size()-1;\n        while(i < j)\n        {\n            if(v[i] == -v[j] || v[j] == -v[i] )\n                return abs(v[i]);\n            if(abs(v[i]) < abs(v[j]))\n            {\n                j--;\n            }\n            else \n                i++;\n        }\n        return -1;\n\n    }\n};\n```
['Two Pointers', 'Sorting', 'C++']