ByteDance Interview Question

It is a two-pointer rank problem.