Sherlock and Cost Time : O(n) Space : O(1) 12345678910long long cost(vector<int> A) { long long small = 0, big = 0, n = A.size(); for(int i = 1; i < n; i++) { auto nbig = max(big + abs(A[i - 1] - A[i]),small + abs(A[i] - 1)); auto nsmall = big + abs(A[i - 1] - 1); big = nbig; small = nsmall; } return max(small, big);}