Pregunta de entrevista de Amazon Web Services

two coding questions, first basic, second harder