Pregunta de entrevista de Microsoft

Two problems with medium difficulty to solve