New Year Chaos

  • + 0 comments

    pyhton 3

    def minimumBribes(q):
        # Write your code here
        total_steps = 0
        n = len(q)
        for i in range(n):
            # Check if the element has moved more than two positions forward
            if q[i] - (i + 1) > 2:
                return print("Too chaotic")
                
            for j in range(max(0, q[i] - 2), i):
                    if q[j] > q[i]:
                        total_steps += 1
        
        return print(total_steps )