Stanford Algorithm Part 1 Problem1