You are viewing a single comment's thread. Return to all comments →
tricky question, the reasoning is far longer than the algorithm
O(n)
int cost(vector<int> B) { pair<int, int> Q = {0, 0}; for (int i=1; i < B.size(); i++) Q = {max(Q.first, Q.second + B[i-1] - 1), max(Q.first + B[i] - 1, Q.second + abs(B[i]- B[i-1]))}; return max(Q.first, Q.second); }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Cost
You are viewing a single comment's thread. Return to all comments →
tricky question, the reasoning is far longer than the algorithm
O(n)