Skip to content

Commit 1eacd5f

Browse files
authored
MinStepsinInfiniteGrid
1 parent f967f45 commit 1eacd5f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Arrays/MinStepsInInfiniteGrid.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// https://www.interviewbit.com/problems/min-steps-in-infinite-grid/
22
// Input : X and Y co-ordinates of the points in order.
33
// Each point is represented by (X[i], Y[i])
4+
/*
45
int Solution::coverPoints(vector<int> &X, vector<int> &Y) {
56
67
int steps = 0, dx, dy, i = 0;
@@ -38,3 +39,18 @@ int Solution::coverPoints(vector<int> &X, vector<int> &Y) {
3839
3940
return steps;
4041
}
42+
*/
43+
44+
int coverPoints(vector<int> &X, vector<int> &Y) {
45+
46+
int size1=X.size(),size2=Y.size(),ans=0;
47+
48+
for(int i=1;i<size1;i++)
49+
50+
{
51+
ans = ans + (abs(X[i]-X[i-1])<abs(Y[i]-Y[i-1])?abs(Y[i]-Y[i-1]):abs(X[i]-X[i-1]));
52+
}
53+
54+
return ans;
55+
}
56+

0 commit comments

Comments
 (0)