Amazon interview question

LeetCode Medium question about queues and summations