Pregunta de entrevista de Meta

complicated sql questions which I cannot solve immediately