Pergunta de entrevista da empresa Tencent

Algorithm question question (I almost forgot it)