CodeEval - Grid Walk problem in Java