Amazon Interview Question

A generic leetcode style question