Problem · Array

Find Maximum Frequency of Number

Learn this problem
EasyGoogleNEW GRADONSITE INTERVIEW
See Google hiring insights

Problem 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[]) → int

Examples

Example 1

nums = [1,2,2,3,3,3,3,4,4,5,6]return = 4
In 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^9
  • nums is sorted in non-decreasing order.

More Google problems

drafts saved locally
public int findMaximumFrequency(int[] nums) {
  // write your code here
}
nums[1,2,2,3,3,3,3,4,4,5,6]
expected4
checking account