Created
June 10, 2022 15:07
-
-
Save piusayowale/baf44c3aaa294524144ecc99edaa5967 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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