Amazon Interview Question

Explain your code from the online assessment (for both problems).