Statistical Mode

EasyStatisticsMathArrayHash Table

Description

Given an array of integers, return the mode: the value that appears most frequently. If several values are tied for the highest frequency, return the smallest of them.

Examples

Input:[1,2,2,3]
Output:2
Explanation:

The value appearing most often is the mode, and when several values share the highest frequency the smallest of them is chosen.

Input:[4,4,1,1]
Output:1
Explanation:

The value appearing most often is the mode, and when several values share the highest frequency the smallest of them is chosen.

Input:[5]
Output:5
Explanation:

The value appearing most often is the mode, and when several values share the highest frequency the smallest of them is chosen.

Constraints

  • 1 ≤ array length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.