Pergunta de entrevista da empresa Amazon

Tricky SQL questions, looking for solution and not for syntactical error.