#C9890. Find the K-th Smallest Element
Find the K-th Smallest Element
Find the K-th Smallest Element
You are given an array of integers and a number k. Your task is to find the k-th smallest element in the array.
The solution should use an algorithm that ideally leverages a heap data structure (max-heap for the k smallest elements) or an equivalent approach.
For example, given the array [7, 10, 4, 3, 20, 15, 2] and k = 3, the k-th smallest element is 4.
Note: The elements in the array may include duplicates; consider them as they are.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains space-separated integers representing the array.
- The second line contains a single integer k.
outputFormat
Output to standard output (stdout) a single integer which is the k-th smallest element in the given array.
## sample7 10 4 3 20 15 2
3
4