FastPrepKth Largest Element without a Heap
Problems/Kth Largest Element without a Heap

Kth Largest Element without a Heap

ByteDance logoByteDance● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report asks for the kth largest value without a heap. The task it points to keeps the ranks of duplicates and asks how to avoid a full sort. We added finite limits on the integers and a function signature. We do not claim the interviewer required one particular selection method. Our version is about 90% the same as the reported question.

You are given an integer array nums and a rank k, starting at 1. Return the kth largest element. Count duplicate values separately, as if the array were sorted from largest to smallest.

Do not use a heap. For this exercise, implement a selection method without fully sorting the input, using the bounded portable interface below.

Function

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

Examples

Example 1

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

The two largest elements are 6 and 5.

Example 2

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

The descending sequence starts 6, 5, 5, 4; duplicates keep separate positions.

Constraints

  • 1 <= nums.length <= 2000.
  • 1 <= k <= nums.length.
  • -10^6 <= nums[i] <= 10^6.

More ByteDance Onsite Interview questions

  • Search a Row- and Column-Sorted MatrixONSITE INTERVIEW · Seen Nov 2026
  • Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Implement Multi-Head AttentionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dynamic Median with Additions and DeletionsONSITE INTERVIEW · Seen Oct 2026
  • Serialize and Deserialize a String Key-Value StoreONSITE INTERVIEW · Seen Oct 2026
  • Binary Tree Maximum Path SumONSITE INTERVIEW · Seen Oct 2026
  • Merge Overlapping IntervalsONSITE INTERVIEW · Seen Oct 2026
  • Tic-Tac-Toe Move WinnersONSITE INTERVIEW · Seen Oct 2026
  • Least Recently Used CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
  • Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
  • Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions

ByteDance interview experiences

  • ByteDance TikTok USDS SWE Intern Interview: 1 Experience
  • ByteDance MLE New Grad Interviews: 1 Experience
  • ByteDance Security SRE Intern Phone Screens: 1 Experience
  • ByteDance USDS New Grad SWE Phone Screen: 1 Experience
  • ByteDance New Grad Data Engineer Video Interviews: 1 Experience
  • ByteDance Trust & Safety Research Scientist Intern: 1 Experience
All ByteDance interview questionsSee ByteDance hiring insights
Saved
class Solution {
    public int kthLargest(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…