Amazon Interview Question

LeetCode Medium question about queues and summations