Pergunta de entrevista da empresa Amazon

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