Observe the solution by Graph


I/p: A: (-7,-1)
B: (-13,-5)

You can see in this graph that horizontal distance is 6 and vertical distance is 4. Thus, by moving 1 step we can make changes in both x and y by 1 step. Thus, here 4 will be reached first hence we need to take max out of these two (i.e. horizontal and vertical).

Code snippet:

    int ans=0;
    for(int i=0;i<A.size()-1;i++)
    return ans;