You are viewing a single comment's thread. Return to all comments →
C++
void minimumBribes(vector<int> q) { int bribes = 0; for (int i = q.size()-1; i >= 2; i--) { if(q[i-2] > q[i-1]){ int temp = q[i-1]; q[i-1] = q[i-2]; q[i-2] = temp; bribes ++; } if(q[i-1] > q[i]){ int temp = q[i]; q[i] = q[i-1]; q[i-1] = temp; bribes ++; } if(q[i] != i+1){ cout << "Too chaotic" << '\n'; return; }
} cout << bribes << '\n';
}
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
C++
}