Pregunta de entrevista de Amazon

LeetCode Medium question about queues and summations