Skip to content

Commit e10a2bd

Browse files
author
Pranjal
authored
Merge pull request #10 from pockemon/master
MinStepsinInfiniteGrid
2 parents 84fea2e + c20c66d commit e10a2bd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Arrays/MinStepsInInfiniteGrid.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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+
5+
// Explanatory code
6+
/*
47
int Solution::coverPoints(vector<int> &X, vector<int> &Y) {
58
69
int steps = 0, dx, dy, i = 0;
@@ -38,3 +41,19 @@ int Solution::coverPoints(vector<int> &X, vector<int> &Y) {
3841
3942
return steps;
4043
}
44+
*/
45+
46+
// Concise code
47+
int coverPoints(vector<int> &X, vector<int> &Y) {
48+
49+
int size1=X.size(),size2=Y.size(),ans=0;
50+
51+
for(int i=1;i<size1;i++)
52+
53+
{
54+
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]));
55+
}
56+
57+
return ans;
58+
}
59+

0 commit comments

Comments
 (0)