Tencent Interview Question

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