Find the largest positive integer in an array whose negative also appears in the array.
Given an integer array, return the largest positive value such that both and appear in the array.
If no such value exists, return .
The answer is based on the absolute value of matching positive/negative pairs, but only positive integers are considered as candidates.
nums.k for which both k and -k exist in nums.-1.1 <= nums.length.Example 1
Input
nums = [-1, 2, -3, 3]
Output
3
Explanation
Both 3 and -3 appear, and 3 is the largest positive integer with its negative present.
Example 2
Input
nums = [-1, 10, 6, 7, -7, 1]
Output
7
Explanation
The pairs are 1 and -1, and 7 and -7. The largest valid positive integer is 7.
Example 3
Input
nums = [-10, 8, 6, 7, -2, -3]
Output
-1
Explanation
No positive integer has its negative also present.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.