KCG interview question

Puzzles, math, algorithms