Google interview question

Coding question solved with math and sliding window.