Problem Β· Array

Kth Smallest in Subarray πŸ’

Learn this problem
● MediumAmazonOA
See Amazon hiring insights

Problem statement

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

Function

kthSmallestInSubarray(arr: int[], k: int, m: int) β†’ int[]

Examples

Example 1

arr = [3, 1, 4, 2]k = 2m = 3return = [3, 2]
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.

More Amazon problems

drafts saved locally
public int[] kthSmallestInSubarray(int[] arr, int k, int m) {
    // write your code here
}
arr[3, 1, 4, 2]
k2
m3
expected[3, 2]
checking account