Time Complexity · #45 · 2026-05-19
What's the Big-O?
JavaScript ·Difficulty 3/3
How to play
Read the code and pick its time complexity from four Big-O choices. Think about loops, recursion, and hidden costs. Press 1–4 or click to answer.
What is the amortized cost per increment over n increments?
function incrementBinary(bits) {
let i = 0;
while (i < bits.length && bits[i] === 1) {
bits[i] = 0;
i++;
}
if (i < bits.length) bits[i] = 1;
return bits;
}
// Called n times starting from all zeros:
const counter = new Array(32).fill(0);
for (let j = 0; j < n; j++) {
incrementBinary(counter);
}
Loading your progress...
Press 1 through 4, or tap a numbered choice, to answer. Back to hub