As reported: SentinelOne Senior Software Engineer (India, remote), 2025, technical round 1 (one hour): after Java questions on
equals/hashCodeand sets, one DSA problem — count the most-occurring element — where the candidate proposed three approaches.
Given an integer array nums, return the element that occurs most often. If several elements share the highest count, return the smallest of them.
Be ready to describe three different approaches and their trade-offs.
Example 1
nums = [3,1,3,2,1,3]
Output: 3
3 appears three times, 1 twice, 2 once.
Example 2
nums = [4,4,7,7,2]
Output: 4
4 and 7 both appear twice; the smaller one wins.
Constraints: 1 <= nums.length <= 10^5, -10^9 <= nums[i] <= 10^9.
Code runner format: one JSON array, nums. Implement mostFrequent(nums) returning an integer.