Skip to content

Instantly share code, notes, and snippets.

@piusayowale
Created June 10, 2022 15:07
Show Gist options
  • Save piusayowale/baf44c3aaa294524144ecc99edaa5967 to your computer and use it in GitHub Desktop.
Save piusayowale/baf44c3aaa294524144ecc99edaa5967 to your computer and use it in GitHub Desktop.
void minimumBribes(vector<int> q) {
bool chaotic = false;
int bribes = 0;
for (int i = 0; i < q.size(); i++) {
if (q[i] - (i+1) > 2) { chaotic = true; }
for (int j = q[i] - 2; j < i; j++) {
if (q[j] > q[i]) { bribes++; }
}
}
if(chaotic == true){
std::cout << "Too chaotic\n";
} else {
std::cout << bribes << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment