Finished version of CodeEval Query Board problem