TuSimple Interview Question

leetcode problem and calculate complexity