← 返回 goldmansachs 的题目列表Find k-th Smallest Element in Array
类型:online_judge
goldmansachs
Programming Task: Find Order Statistic
Given an array of n distinct integers, write a function to return the k-th smallest element in it.
Input
An integer array arr, with length n, 1 <= n <= 1000, and array elements 1 <= arr[i] <= 1000000.
An integer k, representing the k-th smallest element after sorting, 1 <= k <= n.
Output
An integer, representing the k-th smallest element in the sorted array.
Example
Input: arr = [7, 10, 4, 3, 20, 15], k = 3 Output: 7
Input: arr = [3, 1, 2, 1, 4, 2, 5], k = 2 Output: 2
Ensure that your code meets the worst-case time complexity requirements.
Example
Input
7
7 10 4 3 20 15 1
3