Think Chess (king's ability vs rook's ability)


#1

int NSteps(int x1, int x2, int y1, int y2)
{
// We have the ability to move diagonally as well (like a king in chess board)
// which means we can increment (or decrement) x AND y by 1 in a single step

// if we could only move like a rook, we would do (x2 - x1) + (y2 - y1)
return max (abs(x2 - x1), abs(y2 - y1));

}

int Solution::coverPoints(vector &A, vector &B) {
int i, N;
int nsteps = 0;
N = A.size();

for (i = 1; i < N; i++) {
    nsteps += NSteps(A[i-1], A[i], B[i-1], B[i]);
}

return nsteps;

}