Pregunta de entrevista de TuSimple

some algorithm question, leedcode medium-hard level