Pergunta de entrevista da empresa TuSimple

some algorithm question, leedcode medium-hard level