Solution for Facebook Programming Challenge https://facebook.interviewstreet.com/recruit/challenges Answer got from www.careercup.com/question?id=12698695