Number of Times Binary String Is Prefix-Aligned LeetCode solution in JavaScript

1
var numTimesAllBlue = function (flips) {
2
const flipped = new Array(flips.length).fill(0);
3
let prefixAlignedCount = 0;
4
flips.forEach((i, step) => {
5
flipped[i - 1] = 1;
6
if (isPrefixAligned(step)) {
7
++prefixAlignedCount;
8
}
9
});
10
return prefixAlignedCount;
11

12
function isPrefixAligned(step) {
13
for (let i = 0; i < flips.length; ++i) {
14
if ((i < step && flipped[i] === 0) || (i > step && flipped[i] === 1)) {
15
return false;
16
}
17
}
18
return true;
19
}
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0