Domanda di colloquio di Tencent

SQL question and one basic algorithm that needs to be fully written in python.