Thought Machine interview question

to answer an algorithm question