Search
 
SCRIPT & CODE EXAMPLE
 

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)
   }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to create a debounce higher order function 
Javascript :: how to parse arguments to a promise in javascript 
Javascript :: how to refrence schema in my mongoose schema with populate function 
Javascript :: regular expression for spanish date 
Javascript :: form handling in next js 
Javascript :: mongo look for substring of field 
Javascript :: composer json schema download 
Javascript :: add google maps nuxt js 
Javascript :: await multiple promises 
Javascript :: .catch() in promise will aslo return a promise 
Javascript :: nuxt js index.html not found 
Javascript :: jquery show div class 
Javascript :: how to make local storage read only site:stackoverflow.com 
Javascript :: create extern to be usable in c# 
Javascript :: To disable server-to-server and REST tools like Postman to access our API - Remove !origin from your if statement. 
Javascript :: validate vpa api razorpay stackoverflow 
Javascript :: delete nth node from end 
Javascript :: dict equivalent js 
Javascript :: How to Define a Function using Function Declaration in javascript 
Javascript :: weakset use cases javaScript 
Javascript :: multiple images gallery after clicking image javascript 
Javascript :: volta node list 
Javascript :: ajax form submit, gather all data onece 
Javascript :: javascript reduce mdn 
Javascript :: onSeek video getting paused 
Javascript :: Scale to fit 
Javascript :: port for sqlexpress not found in desktop node.js 
Javascript :: js create an object from another object with some keys removed 
Javascript :: restart my react -Dom 
Javascript :: convert string to moment date 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =