Domanda di colloquio di Amazon

Solve this SQL question and the expected results