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

Kth Largest Element in an Array

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The round is not named in the review. It describes a Microsoft software engineering internship interview process with at least two problems, and the author says they did not find an optimized solution for the second. The review lists a k-th largest element question by name only. The author calls it easy and links it to heaps.

Here you get an integer array of 1 to 10^4 values from -10^4 to 10^4 and k with 1 <= k <= n. Equal values count separately, and you return the k-th largest value.

Our version is about 95% the same as the reported question.

Given an integer array nums and an integer k, return the k-th largest element of the array.

This is the element in position k when the array is sorted from largest to smallest, so equal values count separately. It is not the k-th largest distinct value.

Function

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

Examples

Example 1

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

From largest to smallest the values are 5, 4, 3, 2, 1. The 2nd largest is 4.

Example 2

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

From largest to smallest: 4, 4, 1. Equal values count separately, so the 2nd largest is the second 4.

Example 3

nums = [7]k = 1return = 7

With one element, the 1st largest is that element.

Constraints

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

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey 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 Largest Values with a HeapMeta · ONSITE INTERVIEWMeta interview questions
  • Top K Frequent ElementsCapgemini · ONSITE INTERVIEWCapgemini interview questions
  • Select K Paired Indices for Maximum ScoreAmazon · ONSITE INTERVIEW
  • Kth Largest Element in an ArrayOneTrust · ONSITE INTERVIEW

Interview reports that mention this question

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int findKthLargest(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…