FastPrepKth Largest Element: Return Its Original Index
Problems/Kth Largest Element: Return Its Original Index

Kth Largest Element: Return Its Original Index

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The report links the well-known kth-largest task but asks for the original index instead of the value. It does not say how to break ties for the index. Here, equal values are ranked by their original positions. Our version is about 90% the same as the reported question.

Given an integer array nums and a one-based rank k, return the original zero-based index of its kth largest occurrence. Duplicate occurrences occupy separate ranks.

Rank entries by larger value first. When values are equal, rank the entry with the smaller original index first. For example, if nums = [5, 5, 5], the indices in rank order are [0, 1, 2]. Return the index at rank k. Do not change nums.

Function

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

Examples

Example 1

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

The descending values are 6 at index 4 and 5 at index 3, so rank two returns index 3.

Example 2

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

Equal fives occupy the first three ranks in original-index order 0, 1, 2.

Example 3

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

Ranks one through four have values 6, 5, 5, and 4; the value 4 was at original index 5.

Constraints

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

More Meta Onsite Interview questions

  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • 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
  • Kth Largest Element in an ArrayOneTrust · ONSITE INTERVIEW

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int kthLargestIndex(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…