Pregunta de entrevista de Bayer

Solved two basic algorithm questions