Pregunta de entrevista de Microsoft

1 coding question which was pretty straight forward