Company: Amazon_8aug
Difficulty: medium
Medians Problem Description A new Amazon intern encountered a challenging task. Currently, the intern has n integers, where the value of the i-th element is represented by the array element values[i] . The intern is curious to play with arrays, and subsequences are what he asks you to join him. Given n integer array values and an integer k , the intern needs to find the maximum and minimum median overall subsequences of length k . Function Description 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 Example 1: Input: n = 3, values = [1, 2, 3], k = 2 Output: [2, 1] Explanation: The subsequences of length k=2 and their medians are: [1, 2] has a median of 1 . [1, 3] has a median of 2 . [2, 3] has a median of 2 . Here, the maximum median present is 2 and the m