← Whiteboard questions

Pattern

Sliding Window

Use a window when the answer is a run of neighbouring items that must keep some property. Grow the window on the right and shrink it from the left when the property breaks. The usual cost is O(n) time, because each item enters and leaves once.

Sliding Window interview questions and solutions