Domanda di colloquio di TuSimple

some algorithm question, leedcode medium-hard level