Pregunta de entrevista de Amazon

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