You are viewing a single comment's thread. Return to all comments →
Passes all samples , but fails everything else. Any tips fellas ?
function minimumBribes(q) { let bribes = 0 for(let i = 0; i < q.length; i++){ if((q[i]-1) != i && (q[i]-1) > i || q[i] > q[i + 1]){ if(Math.abs((q[i]-1) - i) > 2){ console.log("Too chaotic") bribes = 0 break; } else { if(q[i] > q[i + 1] && i == q.length - 2){ bribes++ } else { bribes += Math.abs((q[i]-1) - i) } } } } if(bribes > 0){ console.log(bribes) } }
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
Passes all samples , but fails everything else. Any tips fellas ?