InterviewBit - Min steps in infinite grid  

by ne on 2020-12-02 under Algo

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 !