Princeton Algorithms I - Exercise 3