Thought Machine interview question

One sliding window and one graph question, medium difficulty