Amazon Interview Question

SWE leetcode question around easy-medium difficultly.