Pergunta de entrevista da empresa Microsoft

1 coding question which was pretty straight forward