You are viewing a single comment's thread. Return to all comments →
C# solution to reverse the bribes and count them:
if (Enumerable.Range(1, q.Count).Any(p => q[p - 1] - p >= 3)) { Console.WriteLine("Too chaotic"); return; } var (i, swaps) = (0, 0); while (i < q.Count) { if (q[i] - i - 1 > 0) { var j = q.IndexOf(i + 1, i + 1) - i; while (j > 0) { (q[i + j], q[i + j - 1], j, swaps) = (q[i + j - 1], q[i + j], j - 1, swaps + 1); } } i++; } Console.WriteLine(swaps.ToString());
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# solution to reverse the bribes and count them: