Microsoft interview question

Algorithm question in mid to hard level