Leetcode #1985: Find the Kth Largest Integer in the Array
In this guide, we solve Leetcode #1985 Find the Kth Largest Integer in the Array in Python and focus on the core idea that makes the solution efficient.
You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Problem Statement
You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.
Quick Facts
- Difficulty: Medium
- Premium: No
- Tags: Array, String, Divide and Conquer, Quickselect, Sorting, Heap (Priority Queue)
Intuition
We need to repeatedly access the smallest or largest element as the input changes.
A heap provides fast insertions and removals while keeping order.
Approach
Push candidates into the heap as you scan, and pop when you need the best element.
Keep the heap size bounded if the problem requires a top-k structure.
Steps:
- Push candidates into a heap.
- Pop the best candidate when needed.
- Maintain heap size or invariants.
Example
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".
Python Solution
class Solution:
def kthLargestNumber(self, nums: List[str], k: int) -> str:
return nlargest(k, nums, key=lambda x: int(x))[k - 1]
Complexity
The time complexity is or , where is the length of the array. The space complexity is or .
Edge Cases and Pitfalls
Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.
Summary
This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.