Computer scienceProgramming languagesJavaInterview preparationAlgorithms and problem solving techniques

Understand the problem

kth largest element

Report a typo

You are given an integer array nums and an integer k. Return the kth largest element in the array.

For the kth largest element problem, each test case consists of two lines: a list of integers and the integer k.

Sample Input 1:

3 2 1 5 6 4
2

Sample Output 1:

5
Write a program in Java 17
import java.util.Arrays;
import java.util.Scanner;

class KthElement{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] nums = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int k = scanner.nextInt();

//write your code here

}
}
___

Create a free account to access the full topic