#1985

Find the Kth Largest Integer in the Array

specialist · 915 · lc medium +31 · verified · 47.6% accepted · 1,365 likes · top 32%

Description

You have an array of numeric strings nums where each string encodes a non-negative integer with no leading zeros, and an integer k. Duplicates are counted as separate entries when ranking.

Return the string that represents the k-th largest integer in nums.

Example 1:

Input: nums = ["3","6","7","10"], k = 4
Output: "3"
Explanation:
The numbers in nums sorted in non-decreasing order are ["3","6","7","10"].
The 4th largest integer in nums is "3".

Example 2:

Input: nums = ["2","21","12","1"], k = 3
Output: "2"
Explanation:
The numbers in nums sorted in non-decreasing order are ["1","2","12","21"].
The 3rd largest integer in nums is "2".

Example 3:

Input: nums = ["0","0"], k = 2
Output: "0"
Explanation:
The numbers in nums sorted in non-decreasing order are ["0","0"].
The 2nd largest integer in nums is "0".

Code

1
2
3