Problem 213620 · easy · Phase 02 Linear Data Structures

Most Common Value, Smallest Wins

hash maps · counting · tie-breaking

Return the value that appears most often in nums. If several values are tied for the highest count, return the smallest of them. Return None for an empty list.

Examples

Input:  nums = [4, 1, 4, 1, 7]
Output: 1
Explanation: 4 and 1 both appear twice; 1 is smaller.

Input:  nums = [3, 3, 2]
Output: 3

Constraints

  • 0 <= len(nums) <= 10**5
  • Target complexity: O(n) time.

Goals

  • Find the maximum of a frequency table
  • Apply an explicit tie-breaking rule
Starting Python…