Sliding Window Median
Reported by candidates from Notion's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at Notion's Sliding Window Median is sorting every window from scratch. It passes the examples, then dies on 50000 elements. Notion reported this one in October 2025, and it's a classic sliding-window problem with a data structure twist. You need the median of every length-k window, which means keeping the window ordered as it slides. If you have the invite and 48 hours, learn the two-heap or ordered-structure approach cold. StealthCoder sits invisibly on your screen during the live OA as a safety net if your mind goes blank on the rebalancing logic.
The problem
Given an integer array nums and a window size k, return the median of every contiguous window of length k, from left to right. For an odd-length window, the median is its middle sorted value. For an even-length window, it is the average of the two middle sorted values. Function medianSlidingWindow(nums: int[], k: int) → double[] Examples Example 1 nums = [1,3,-1,-3,5,3,6,7] k = 3 return = [1.0,-1.0,-1.0,3.0,5.0,6.0] Sorting each length-three window exposes its middle value. Example 2 nums = [1,2] k = 1 return = [1.0,2.0] Each one-element window has that element as its median. Example 3 nums = [1,4,2,3] k = 4 return = [2.5] The two middle sorted values are 2 and 3. Constraints 1 <= nums.length <= 50000 -1000000000 <= nums[i] <= 1000000000 1 <= k <= nums.length
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is maintaining the window in sorted order without re-sorting. Two approaches work. First, two heaps: a max-heap for the lower half and a min-heap for the upper half, with lazy deletion using a hash map of pending removals. Second, a sorted list with binary search: insert the new value with bisect, remove the outgoing value by binary searching its position, then read the middle. Each slide costs O(log k) for the search, plus shifting if you use an array. Common pitfalls: integer overflow when averaging two values near 1e9, so add as doubles or use a/2 + b/2. Another is forgetting that duplicates exist, which breaks naive removal from a heap. Also watch heap size balance after every removal. If you freeze on lazy deletion mid-OA, StealthCoder is your hedge, giving you a working structure to adapt.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Sliding Window Median cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as sliding window median. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Notion's OA.
Notion reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sliding Window Median FAQ
How hard is Sliding Window Median really?+
It's a hard-tier problem, but the idea is short. Keep the window sorted as it slides. The difficulty is implementation: removal, duplicates, and balancing. If you've seen Find Median from Data Stream, you're halfway there.
What's the trick to avoid timing out?+
Don't sort each window. With n up to 50000, that's too slow. Keep a sorted structure and update it per slide, either with two heaps plus lazy deletion or a sorted array using binary search to insert and remove.
How do I handle even-length windows and overflow?+
For even k, average the two middle values. Values go up to 1e9 in magnitude, so adding two can overflow a 32-bit int. Cast to double or long before adding, then divide by 2.0 to get the right result.
Is the sliding window pattern still asked at Notion?+
This one was reported for Notion in October 2025, so yes, it's current. Expect window problems that need a supporting structure like a heap, deque, or ordered list, not only a simple two-pointer sweep.
How do I prepare in 48 hours?+
Write the sorted-list version first since it's simplest, using binary search for insert and delete. Test on the three examples plus duplicates and k equals 1. Then try the two-heap version with lazy deletion if you have time left.