Amazon interview question

The coding interview problem was a leetcode hard.