Problem · Array
Find Maximum Frequency of Number
Learn this problemProblem statement
Given a sorted array, find the maximum frequency of a number.
Example: [1,2,2,3,3,3,3,4,4,5,6] : Answer: 4 (3 is repeated 4 times).
O(N) is a straightforward solution. Asked if the performance can be improved.
Function
findMaximumFrequency(nums: int[]) → intExamples
Example 1
nums = [1,2,2,3,3,3,3,4,4,5,6]return = 4In the given array, the number 3 appears the maximum number of times, which is 4 times.
Constraints
1 <= nums.length <= 10^5-10^9 <= nums[i] <= 10^9numsis sorted in non-decreasing order.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026