Find the Kth Largest Integer in the Array

Try to solve the Find the Kth Largest Integer in the Array problem.

Statement

Given an array of strings, nums, where each string represents an integer without leading zeros, and an integer k, your task is to find and return the string representing the kth^{th} largest integer in the array.

Note: Treat duplicate integers as distinct entities. For instance, if nums =[“2”, “3”, “3”]= [\text{\lq\lq2\rq\rq, \lq\lq3\rq\rq, \lq\lq3\rq\rq]}, the first largest integer is “3”\text{\lq\lq3\rq\rq}, the second largest is also “3”\text{\lq\lq3\rq\rq}, and the third largest is “2”\text{\lq\lq2\rq\rq}.

Constraints:

  • 1<=1 <= k <=<= nums.length <=103<= 10^3

  • 1<=1 <= nums[i].length <=100<= 100

  • nums[i] consists of only digits.

  • nums[i] will not have any leading zeros.

Examples

Press + to interact
canvasAnimation-image
1 of 3

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Find the Kth Largest Integer in the Array

1

You are given nums = [“4”, “2”, “9”, “3”] and k = 2. What is the output?

A)

“2”

B)

“3”

C)

“4”

D)

“9”

Question 1 of 30 attempted

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding on how to solve this problem.

Drag and drop the cards to rearrange them in the correct sequence.

Try it yourself

Implement your solution in the following coding playground. 

Press + to interact
Java
usercode > Solution.java
public class Solution
{
public static String kthLargestInteger (String[] nums, int k)
{
// Replace this placeholder return statement with your code
return "";
}
}
Find the Kth Largest Integer in the Array

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.