Leetcode Problem 2441. Largest Positive Integer That Exists With Its Negative
2441. Largest Positive Integer That Exists With Its Negative
Leetcode Solutions
Using HashSet to Find Maximum k with Negative Counterpart
Initialize a HashSet to store the numbers from the array.
Initialize a variable maxK to -1 to keep track of the maximum k found.
Iterate through each number in the array.
a. If the number is positive, check if its negative counterpart is in the HashSet.
b. If the negative counterpart exists, update maxK with the maximum of maxK and the current number.
After the iteration, return maxK if it's not -1, otherwise return -1.
Sorting and Two Pointers to Find Maximum k with Negative Counterpart