Tencent interview question

Algorithm question question (I almost forgot it)