Titan Company interview question

Difficult SQL queries.