FastPrepMaximize Element Frequency
Problems/Maximize Element Frequency

Maximize Element Frequency

Goldman Sachs logoGoldman Sachs● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Our version is about 99% the same as the reported question.

Given an array of positive integers nums and a positive integer k, you may perform at most k operations.

In one operation, choose one index and increase nums[i] by 1.

Return the maximum possible frequency of any value in the array after performing the operations. The frequency of a value is the number of times it appears.

Function

maxFrequency(nums: int[], k: int) → int

Examples

Example 1

nums = [1,3,5,7,8,9,10,15]k = 6return = 4

Increase 7 three times, 8 twice, and 9 once. The array then contains four occurrences of 10, using exactly 6 operations.

Example 2

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

Increase 1 to 4 using 3 operations and increase 2 to 4 using 2 operations. All three elements become 4.

Example 3

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

Two elements can be made equal, for example by increasing 8 to 13. Making any three elements equal requires more than 5 operations.

Example 4

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

No value can reach another array value with only 2 increments, so the maximum frequency remains 1.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^5
  • 1 <= k <= 10^5

More Goldman Sachs Onsite Interview questions

  • Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
  • Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Meeting Rooms Without a Sweep LineONSITE INTERVIEW · Seen Oct 2026
  • First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Root of the Largest TreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Dungeon HealthONSITE INTERVIEW · Seen Sep 2026
  • Insert, Delete, And Get Random In Constant TimeONSITE INTERVIEW · Seen Sep 2026
  • Least Recently Used CacheONSITE INTERVIEW · Seen Sep 2026
  • Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEW
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEW
  • Count Zero Request ServersSalesforce · ONSITE INTERVIEW
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEW
  • Unit-Weight Knapsack with Limited QuantitiesGoogle · ONSITE INTERVIEW
  • Reduce Array Size to At Most HalfMicrosoft · ONSITE INTERVIEW
  • Select K Paired Indices for Maximum ScoreAmazon · ONSITE INTERVIEW
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Minimum Removals for Non-Overlapping IntervalsByteDance · PHONE SCREEN · ONSITE INTERVIEW
  • Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEW
See Goldman Sachs hiring insights
Saved
class Solution {
    public int maxFrequency(int[] nums, int k) {
        // write your code here
    }
}
Checking account…