Problem statement

https://binarysearch.com/problems/K-and-K/

Solution

Just put all numbers to set and check conditions.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, nums):
        s = set(nums)
        ans = -1
        for x in s:
            if -x in s:
                ans = max(ans, x)
        return ans