A rolling median is robust to spikes, but recomputing it from scratch is slow. Implement rolling_median(x, k) returning medians for each full window x[i : i + k] (length n - k + 1).
A simple correct approach keeps a sorted list of the current window and uses bisect to insert the new value and remove the old one, giving O(k) per step. (The two-heap approach with lazy deletion is O(log k) and a good extension.)