Domanda di colloquio di Tencent

Algorithm Problem Solving at the end.