Valve Corporation interview question

General algorithm questions. Implement X.