You are viewing a single comment's thread. Return to all comments →
JS
function minimumBribes(queue) { let result = "Too chaotic"; if (! queue.some((value, index) => value - index > 3)) { let bribes = 0; for (let _ in [false, false]) { for (let index = queue.length - 1; index > 0; index--) { if (queue[index] < queue[index - 1]) { queue[index] += queue[index - 1]; queue[index - 1] = queue[index] - queue[index - 1]; queue[index] -= queue[index - 1]; bribes++; } } } result = bribes; } console.log(result); }
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 →
JS