Toptal Interview Question

Sliding window problem + simple data structure question.