Simplify the solution a bit by 1) combine two branches 2) move count max into loop condition directly