TuSimple Interview Question

DP problem and a array problem