Yahoo interview question

Difficult SQL query question.