[problem 10] reduce to 1sec algorithm