TuSimple Interview Question

very similar to Leetcode 1463, cherry pick up II