Amazon interview question

Leetcode medium to hard, followed by behavioral round