FastPrepKth Largest Element in an Array
Problems/Kth Largest Element in an Array

Kth Largest Element in an Array

Tokopedia logoTokopedia● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names and links this well-known heap problem. Our version is about 99% the same as the reported question.

Given an integer array nums and an integer k, return the kth largest element in sorted order.

Duplicate occurrences count separately. The answer is not the kth distinct value.

Function

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

Examples

Example 1

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

Descending order is [6,5,4,3,2,1], so the second element is 5.

Example 2

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

The duplicate fives occupy two positions, and the fourth largest occurrence is 4.

Constraints

  • 1 <= k <= nums.length <= 100000.
  • -10000 <= nums[i] <= 10000.

More Tokopedia interview questions

  • Validate Binary Search TreeONSITE INTERVIEW · Seen Aug 2021
  • Online Stock SpanONSITE INTERVIEW · Seen Jul 2021
  • Vertical Order Traversal of a Binary TreeONSITE INTERVIEW · Seen Jul 2021
  • Interleaving StringPHONE SCREEN · Seen Jul 2021
  • Delete Node in a BSTPHONE SCREEN · Seen Jul 2021
  • Rotate ImagePHONE SCREEN · Seen Jul 2021

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
  • Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
  • Minimum Meeting Rooms Without a Sweep LineGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Dominant Index with Strict Doubling GapsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Top K Frequent ElementsCapgemini · ONSITE INTERVIEWCapgemini interview questions
All Tokopedia interview questionsSee Tokopedia hiring insights
Saved
class Solution {
    public int findKthLargest(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…