Thought Machine Interview Question

to answer an algorithm question