This problem is from the book Elements of Programming Interviews -- I couldn't seem to find a similar problem