We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
for (let i = 0; i < q.length; i++) {
let current = q[i];
// Check if the person has moved more than 2 places ahead
if (current - (i + 1) > 2) {
console.log("Too chaotic");
return;
}
// Count how many times the current person has been overtaken
// Only check up to two positions behind their original position
for (let j = Math.max(0, current - 2); j < i; j++) {
if (q[j] > current) {
totalBribes++;
}
}
}
console.log(totalBribes);
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
function minimumBribes(q) { let totalBribes = 0;
}
function main() { const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
}