Microsoft interview question

They asked for an algorithm