P7 · 2 seconds · 256 MB
Frequency Mode
Given an integer array `nums`, return its **mode**: the value that appears most often. If several values share that highest frequency, return the **smaller** one. `nums` is never empty.
function mode(nums) → number
CONSTRAINTS
- 1 ≤ nums.length ≤ 10⁵
- -10⁹ ≤ nums[i] ≤ 10⁹
Input: nums = [1, 2, 2, 3]
Output: 2
2 appears twice; every other value appears once.
Input: nums = [3, 1, 3, 1]
Output: 1
1 and 3 both appear twice. The smaller value wins.
Input: nums = [7]
Output: 7
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.