Amazon Interview Question

Write the function immediately