Small solution in Cpp


#1

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

return ans;    

}