Solve problem 2 (naive)
Solve problem 2 (optimal)