Amazon interview question

An algorithm question on leetcode