O(n) solution for Min Steps in Infinite Grid


#1

int Solution::coverPoints(vector &A, vector &B) {
int n=A.size();
double ans=0;
for (int i=1;i<n;i++)
{
ans= ans+abs(abs(A[i]-A[i-1])-abs(B[i]-B[i-1]))+min(abs(A[i]-A[i-1]),abs(B[i]-B[i-1]));
}
return ans;
}