New Year Chaos

  • + 0 comments

    C#

        public static void minimumBribes(List<int> q)
        {
            int b = 0;
            for (int i = q.Count - 1; i > 0; i--)
            {
                for (int j = i; j > i - 2 && j > 0; j--)
                {
                    if (q[i] < q[j - 1])
                    {
                        (q[i], q[j - 1]) = (q[j - 1], q[i]);
                        b++;
                    }
                    
                }
                if (q[i] != i+1)
                {
                    Console.WriteLine("Too chaotic");
                    return;
                }
            }
            Console.WriteLine(b);
        ``}