A new Amazon intern encountered a challenging task. Currently, the intern has n integers, where the value of the ith element is represented by the array element values[i].
The intern is curious to play with arrays and subsequences and thus asks you to join him.
Given an integer, array values, and an integer k, the intern needs to find the maximum and minimum median overall subsequences of length k.
Complete the function medians in the editor below.
medians has the following parameter(s):
int values[n]: the value of integers.int k: the given integer
Returns
int[]: the maximum and minimum overall subsequences of length k in the form [maximum median, minimum median].
Examples
01 · Example 1
nums = [1, 2, 3] k = 2 return = [2, 1]

We can see that the max median is 2 and the min median is 1.
02 · Example 2
nums = [56, 21] k = 1 return = [56, 21]

Sometimes, an image tells all.. 🤫
03 · Example 3
nums = [16, 21, 9, 2, 78] k = 5 return = [16, 16]

A picture is worth a thousand words.. 🤧
Constraints
1 ≤ n ≤ 10^50 ≤ nums[i] ≤ 10^91 ≤ k ≤ n
More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int[] medians(int[] nums, int k) {
// write your code here
}
nums[1, 2, 3]
k2
expected[2, 1]
sign in to submit