Amazon Interview Question

(easy level leetcode problem)