Pergunta de entrevista da empresa Google

Coding question solved with math and sliding window.