New Year Chaos

  • + 0 comments

    kudos to the author of this site https://csanim.com/tutorials/hackerrank-solution-new-year-chaos

    realy help me with optimized solution

    def minimumBribes(q):
        # Write your code here
        bribes = 0
        q = [0] + q
        for i,val in enumerate(q):       
            if val - i > 2:
                print('Too chaotic')
                return
            
            bribes += sum([i > val for i in q[max(val-1,0):i]])              
        
        print(bribes)