P14 · 1 second · 256 MB

Distinct Numbers

Given an array of integers `a`, return how many distinct values it contains. Order does not matter. The empty array has 0 distinct values.

function distinctNumbers(a) → number

CONSTRAINTS

  • 0 ≤ a.length ≤ 10⁴
  • -10⁹ ≤ a[i] ≤ 10⁹
Input: a = [4, 1, 4, 2, 1]
Output: 3
The values are 1, 2, and 4.
Input: a = []
Output: 0
1
2
3
4
5
6
7
8

Arena judges JavaScript in a Web Worker (1s wall-clock, then TLE). Samples are public; submit runs hidden tests too. C++/Python is a later swarm package.