Pregunta de entrevista de Google

Coding question solved with math and sliding window.