Domanda di colloquio di Morgan Stanley

puzzles, math, sql question with join, standard c/c++