Running Medians
Updated
Problem statement
Given an integer array nums, process its values from left to right. After each insertion, return the median of all values seen so far.
For an even number of values, the median is the average of the two middle values. Return one median for every prefix of nums.
Function
runningMedians(nums: int[]) → double[]Examples
Example 1
nums = [5,15,1,3]return = [5.0,10.0,5.0,4.0]The sorted prefixes have medians 5, 10, 5, and 4.
Example 2
nums = [2,2,2]return = [2.0,2.0,2.0]Every prefix consists only of the value 2.
Constraints
1 <= nums.length <= 100000-10^9 <= nums[i] <= 10^9- Results use absolute tolerance
1e-12
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Top K With a Deterministically Noisy Comparator (MLE)Mercor · ONSITE INTERVIEWMercor interview questions
- Meeting Rooms III: Most Booked RoomGoogle · ONSITE INTERVIEWGoogle interview questions
- Find the Safest Path in a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Employee Free TimeIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Minimum Refueling StopsUber · ONSITE INTERVIEWUber interview questions
- Sliding Window MedianNotion · ONSITE INTERVIEWNotion interview questions
- Order Matching on ExecuteSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
- Sliding Window MedianBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Running Median of a StreamPeopleStrong · PHONE SCREEN · ONSITE INTERVIEWPeopleStrong interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions