TuSimple interview question

A coding question. Need to implement it.