Amazon Interview Question

two coding questions of difficulty level leetcode medium