Question d’entretien chez Microsoft

Algorithm question in mid to hard level