Provided solution will not work for a particular test case


#1

For given input, editorial solution will not work.
A : [ 0, 1, 1, 2 ]
B : [ 0, 1, 2, 2 ]

As per the max(X,Y) logic, it is returning 3. But expected value is 2.

Given three points are: (0, 0), (1, 1), (1, 2) and (2,2).
It takes 1 step to move from (0, 0) to (1, 1). It takes one more step to move from (1, 1) to (2, 2).


#2

you have skipped the point (1, 2), whereas it is mandatory to visit all the points in the mentioned order.