Yahoo Interview Question

Difficult SQL query question.