InterviewBit - Min steps in infinite grid
by ne on 2021-09-29 under Algo/DS/Problems
This problem is a property of InterviewBit (www.interviewbit.com).
Full details of the question, and if you want to try it out yourself, proceed to interviewbit : https://www.interviewbit.com/problems/min-steps-in-infinite-grid/
Here's the implementation:
public class Solution {
public int coverPoints(int[] A, int[] B) {
int tot=0;
for(int i=1;i<A.length;i++){
for(int j=1;j<B.length;j++){
int x=A[i];
int y=B[j];
int x0 = A[i-1];
int y0 = B[j-1];
tot+=Math.max(Math.abs(x-x0),Math.abs(y-y0));
}
}
return tot;
}
}
Happy Coding !