Amazon interview question

leetcode, leetcode hard optimal not required