Space-Bounded Kth Largest Element
Updated
Problem statement
Given an unordered integer array nums and a one-based rank k, return its kth largest value. Duplicate occurrences occupy separate ranks.
Do not sort the array. Solve the follow-up using a rank-selection heap containing at most ceil(nums.length / 2) values. The supplied array is already in memory; this limit concerns additional selection storage.
Function
findKthLargest(nums: int[], k: int) → intExamples
Example 1
nums = [3,2,1,5,6,4]k = 2return = 5Only 6 is larger than 5.
Example 2
nums = [3,2,3,1,2,4,5,5,6]k = 4return = 4The descending ranks begin 6, 5, 5, 4; equal values occupy separate ranks.
Example 3
nums = [8,-1,3,5,2]k = 5return = -1For a rank near the end, retaining the smallest values uses less storage.
Constraints
1 <= nums.length <= 100000.1 <= k <= nums.length.-1000000000 <= nums[i] <= 1000000000.
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- 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
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Defer Expenses to Preserve BalanceDRW · PHONE SCREENDRW interview questions
- Select the Top User MatchesDuolingo · PHONE SCREENDuolingo interview questions
- Meeting Rooms IIQuince · PHONE SCREENQuince interview questions
- Kth Largest Element in an ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Meeting Rooms IISecuronix · PHONE SCREEN
- Minimize Array Sum After K Halving OperationsDocuSign · PHONE SCREENDocuSign interview questions
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