Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
yield + deque solution in Clear category for Median of Three by Alexey.K.
from collections import deque
def median_three(els: list[int]) -> list[int]:
prev_nmbs = deque(maxlen=3)
for item in els:
prev_nmbs.append(item)
if len(prev_nmbs) != 3:
yield item
else:
yield sorted(prev_nmbs)[1]
Jan. 18, 2022