Amazon Interview Question

Interview question is similiar to what you did in leetcode