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.