Microsoft interview question

Algorithm................................................................................................