@Chris-Kawa
ha, the code is good, but does not pas all tests.
it doesn't pass the tests within in the time limit, handling set of numbers up to 100000.
Your code did not execute within the time limits
void swap(std::map<int, int>& countsdata, int &count, int& a, int& b)
{
countsdata[a]++;
int temp = a;
a = b;
b = temp;
count++;
}
void minimumMoves(vector<int> q) {
std::map<int, int> countsdata;
int count = 0;
for (int i = q.size() - 1; i > 0; --i)
{
for (int j = 0; j < i; ++j)
{
if (q[j] > q[j + 1])
swap(countsdata, count, q[j], q[j+1]);
}
}
bool tooChoatic = false;
for (auto& c : countsdata){ // i suspect this is the culprit.
if(c.second > 2){
tooChoatic = true;
break;
}
}
if(tooChoatic){
std::cout << "Too chaotic" << std::endl; // jumped more than 2 positions.
}
else{
std::cout << count << std::endl;
}
}