K-th Largest Value in an Array
Updated
Problem statement
You are given an integer array nums and an integer k. Return the k-th largest value in the array: the value that would sit at position k if the array were sorted from largest to smallest, with position 1 holding the largest value.
Equal values each take their own position, so the answer is not the k-th largest distinct value. For example, in [8,8,3] the second largest value is 8.
Function
kthLargest(nums: int[], k: int) → intExamples
Example 1
nums = [7,-2,15,4,9,4]k = 3return = 7From largest to smallest the values are 15, 9, 7, 4, 4, -2. The third one is 7.
Example 2
nums = [8,8,3,8,1]k = 2return = 8Equal values each count: from largest to smallest the values are 8, 8, 8, 3, 1, so the second largest is 8, not 3.
Example 3
nums = [-5]k = 1return = -5One value: it is the largest. Answer: -5.
Constraints
1 <= k <= nums.length <= 10^4-10^4 <= nums[i] <= 10^4
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- 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
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- 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
- Merge Multiple Sorted StreamsNVIDIA · PHONE SCREENNVIDIA interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions