FastPrepFastPrep
Problem Brief

Kth Smallest in Subarray πŸ’

OA
See Amazon online assessment and hiring insights

Given an array arr, return the kth smallest integer for each subarray of size m.

1Example 1

Input
arr = [3, 1, 4, 2], k = 2, m = 3
Output
[3, 2]
Explanation
In the first subarray of size 3 ([3,1,4]) the 2nd smallest element is 3. In the second subarray of size 3 ([1,4,2]) the 2nd smallest element is 2.
public int[] kthSmallestInSubarray(int[] arr, int k, int m) {
    // write your code here
}
Input

arr

[3, 1, 4, 2]

k

2

m

3

Output

[3, 2]

Sign in to submit your solution.