Function to Find the K-th Number
Time limit0.2sMemory limit512 MB
Given an array of up to 5,000,000 integers and 1-based K, return the element at position K after sorting the array ascending.
- Level
Medium4 of 10
- Topics
- Sorting, Brute force
- Solved
- No attempts yet
Problem
You are given a sequence of size . Write a function that returns the -th number from the front when is sorted in ascending order.
The function you must write is as follows. is given as n, as a, and as k.
- C, C11, C (Clang), C11 (Clang):
int kth(int *a, int n, int k); - C++, C++11, C++14, C++17, C++ (Clang), C++11 (Clang), C++14 (Clang), C++17 (Clang):
int kth(std::vector<int> &a, int k); - Java, Java (OpenJDK):
int kth(int[] a, int k);(class name: Test) - PyPy2, PyPy3:
def kth(a: list, k : int) -> int - Go:
kth(a []int, k int) int