Find Closest Number to Zero Problem

Find Closest Number to Zero Problem — ExecCode Easy DSA Practice

Solve the Find Closest Number to Zero problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an integer array nums of size n, return the number with the value closest to 0 in nums. Your task is to if there are multiple answers, return the number with the largest value.

Examples

Input {"nums": [-4, -2, 1, 4, 8]}; Output 1. Input {"nums": [2, -1, 1]}; Output 1

Constraints

1 <= n <= 1000 -10^5 <= nums[i] <= 10^5

Practice Find Closest Number to Zero free on ExecCode. Browse DSA problems, topic map, and placement guides.