Company: Amazon_29Aug
Difficulty: medium
Get Subarray Median Problem Description Developers at Amazon are working on an application to test the reliability of servers. As a simulation, n requests are sent to the servers, and the size of the i th request is request[i] units. Given an array, requests , and an integer, mid , count the number of subarrays in requests with a median of mid . Note: The median of an array is the middle value in that sorted array. If the size of the array is even, there are 2 middle values. In this case, the median is the element at the smaller index of the two. A subarray of an array is defined as any contiguous segment of the array. Complete the function getSubarrayMedian in the editor below. getSubarrayMedian has the following parameters: int mid : the target median int requests[n] : the sizes of the requests Returns: long int : the number of subarrays of requests with a median of mid Examples Example 1: Input: requests = [1, 2, 3] , mid = 2 All possible subarrays are: [1] , [2] , [3] , [1,2] , [2,