Amazon interview question

A generic leetcode style question