Toptal interview question

Sliding window problem + simple data structure question.