Pregunta de entrevista de Toptal

Sliding window problem + simple data structure question.