Problem · Array

Most Frequent Integer with Smaller Tie-Break

Learn this problem
EasyByteDanceFULLTIMEPHONE SCREEN

Problem statement

Given an integer array nums, return the value that appears most frequently.

If multiple values have the same maximum frequency, return the smallest of those values.

Function

mostFrequentInteger(nums: int[]) → int

Examples

Example 1

nums = [4, 2, 4, 2, 3]return = 2

The values 2 and 4 each appear twice. Because their frequencies tie, return the smaller value, 2.

drafts saved locally
public int mostFrequentInteger(int[] nums) {
  // Write your code here.
}
nums[4, 2, 4, 2, 3]
expected2
checking account