Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

New Year Chaos Solution

function minimumBribes(q) {
    // Write your code here
    if (Array.isArray(q)) {
        let num = 0;
        let chaotic = false;
        
        for(let i=q.length-1; i>=0; i--) {
            if(q[i]-i > 3) chaotic = true
            
            for(let j=q[i]-2; j<i; j++){
                if(q[j] > q[i]) num++
            }
        }
        if(chaotic) console.log("Too chaotic")
        else console.log(num)
   }
}
 
PREVIOUS NEXT
Tagged: #New #Year #Chaos #Solution
ADD COMMENT
Topic
Name
8+4 =