TuSimple Interview Question

One medium to hard level coding problem