Most Frequent Value

L2 Easy Arrays & Hashing
Concept
Finding the maximum in a dictionary mirrors the champion pattern from arrays, with counts taking the role of the compared values.
Return the integer that appears most often in nums. If several integers tie, return the smallest one. If nums is empty, return nil.
Examples
▸ nums = [1, 3, 3, 2, 2]
→ 2
▸ nums = [5]
→ 5
▸ nums = []
→ nil
Progressive Hints
Hint 1 · Nudge
The champion pattern from plain arrays comes back, but now you're ranking by vote count.
Hint 2 · Plan
Build a frequency map. Then scan it, keeping the value with the highest count and preferring the smaller value when counts tie. Return nil when the array is empty.
Hint 3 · Approach
counts = frequency map. Scan the keys tracking the largest count, breaking ties toward the smaller key. Return that key, or nil when the array is empty.
Output
// Run your code to see the output here.