Amazon interview question

A Leetcode Medium Problem - Can't be specific due to NDA