Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c2850ec

Browse files
committedApr 12, 2025
Add solution #1375
1 parent 0deb053 commit c2850ec

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,261 LeetCode solutions in JavaScript
1+
# 1,262 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1047,6 +1047,7 @@
10471047
1372|[Longest ZigZag Path in a Binary Tree](./solutions/1372-longest-zigzag-path-in-a-binary-tree.js)|Medium|
10481048
1373|[Maximum Sum BST in Binary Tree](./solutions/1373-maximum-sum-bst-in-binary-tree.js)|Hard|
10491049
1374|[Generate a String With Characters That Have Odd Counts](./solutions/1374-generate-a-string-with-characters-that-have-odd-counts.js)|Easy|
1050+
1375|[Number of Times Binary String Is Prefix-Aligned](./solutions/1375-number-of-times-binary-string-is-prefix-aligned.js)|Medium|
10501051
1380|[Lucky Numbers in a Matrix](./solutions/1380-lucky-numbers-in-a-matrix.js)|Easy|
10511052
1389|[Create Target Array in the Given Order](./solutions/1389-create-target-array-in-the-given-order.js)|Easy|
10521053
1400|[Construct K Palindrome Strings](./solutions/1400-construct-k-palindrome-strings.js)|Medium|
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* 1375. Number of Times Binary String Is Prefix-Aligned
3+
* https://leetcode.com/problems/number-of-times-binary-string-is-prefix-aligned/
4+
* Difficulty: Medium
5+
*
6+
* You have a 1-indexed binary string of length n where all the bits are 0 initially. We will
7+
* flip all the bits of this binary string (i.e., change them from 0 to 1) one by one. You are
8+
* given a 1-indexed integer array flips where flips[i] indicates that the bit at index i will
9+
* be flipped in the ith step.
10+
*
11+
* A binary string is prefix-aligned if, after the ith step, all the bits in the inclusive range
12+
* [1, i] are ones and all the other bits are zeros.
13+
*
14+
* Return the number of times the binary string is prefix-aligned during the flipping process.
15+
*/
16+
17+
/**
18+
* @param {number[]} light
19+
* @return {number}
20+
*/
21+
var numTimesAllBlue = function(flips) {
22+
let maxFlipped = 0;
23+
let result = 0;
24+
25+
flips.forEach((position, step) => {
26+
maxFlipped = Math.max(maxFlipped, position);
27+
if (maxFlipped === step + 1) result++;
28+
});
29+
30+
return result;
31+
};

0 commit comments

Comments
 (0)
Please sign in to comment.