DEV Community

Karleb
Karleb

Posted on

#2441. Largest Positive Integer That Exists With Its Negative

https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/?envType=daily-question&envId=2024-05-02

/**
 * @param {number[]} nums
 * @return {number}
 */
var findMaxK = function (nums) {
    let k = -1
    let seen = new Set(nums)

    for (const num of nums) {
        if (seen.has(-num)) {
            k = Math.max(k, num)
        }
    }

    return k
};

Enter fullscreen mode Exit fullscreen mode

A very interesting question.

Top comments (0)