Skip to main content
Back to problems
Leetcode
Medium
Arrays
Sorting
Binary Search
Google
Meta
Frequency Of The Most Frequent Element

Make as many elements equal as possible by using a limited number of increment operations.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

You are given an integer array nums and an integer k.

In one operation, you may increment any element of the array by 1. You can perform at most k such operations in total.

Return the maximum possible frequency of any value in the array after performing at most k operations.

A value's frequency is the number of times it appears in the array.

Idea of the task

The best result comes from choosing a target value and using available increments to raise smaller numbers up to that value. Your goal is to find the largest group of elements that can be made equal with no more than k total increments.

Input Format

  • nums: an integer array
  • k: the maximum number of increment operations allowed

Output Format

  • Return an integer representing the maximum achievable frequency.

Constraints

  • 1 <= nums.length
  • 0 <= k
  • Elements are integers
  • Only increment operations are allowed
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1,2,4], k = 5

Output

3

Explanation

Increment 1 by 3 and 2 by 2 to make all elements 4. The frequency of 4 becomes 3.

Example 2

Input

nums = [1,4,8,13], k = 5

Output

2

Explanation

You can make either [1,4] both equal to 4 using 3 operations, or [4,8] both equal to 8 using 4 operations. No group of 3 can be equalized within 5 operations.

Show 1 more example

Example 3

Input

nums = [3,9,6], k = 2

Output

1

Explanation

With only 2 increments, no two numbers can be made equal.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.