Pergunta de entrevista da empresa Meta

complicated sql questions which I cannot solve immediately