FastPrepTop K Frequent Elements with Larger-Value Tie Break
Problems/Top K Frequent Elements with Larger-Value Tie Break

Top K Frequent Elements with Larger-Value Tie Break

Oracle logoOracle● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source omits the callable interface, numeric bounds, and invalid-k behavior. The judged core task matches the visible source at about 95%.

Given an integer array nums and an integer k, return the k most frequent distinct values.

Order the result by decreasing frequency. When two values have the same frequency, the larger value must appear first.

Function

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

Examples

Example 1

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

Example 2

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

All three values occur twice, so the larger values 4 and 2 come first.

Constraints

  • 1 <= nums.length <= 200000
  • -10^9 <= nums[i] <= 10^9
  • 1 <= k <= the number of distinct values in nums

More Oracle problems

  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public int[] topKFrequent(int[] nums, int k) {
      // Write your code here.
    }

}
Checking account…