UC San Diego Interview Question

The most difficult query I had written in SQL.