Code RoomSliding window range
MediumPrep Room Coding #1143

Sliding window range

CodingAlgorithms & data structuresMid–Senior~25 min

Given an integer array nums and a window size k, return for each window the difference (max - min) within that window, as you slide the window from left to right one step at a time. The array has length between 1 and 10^5 and 1 <= k <= len(nums). Return a list of length len(nums) - k + 1.

Implement
window_range(nums: list[int], k: int) → list[int]
Examples
in[[1,3,-1,-3,5,3,6,7],3]out[4,6,8,8,3,4]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[[1,3,-1,-3,5,3,6,7],3][4,6,8,8,3,4]not run yetsample