Leetcode 1491 Solution
This article provides solution to leetcode question 1491 (number-of-times-binary-string-is-prefix-aligned)
Access this page by simply typing in "lcs 1491" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/number-of-times-binary-string-is-prefix-aligned
Solution
class Solution:
def numTimesAllBlue(self, light: List[int]) -> int:
curr = 0
ans = 0
for i, pos in enumerate(light):
curr = max(curr, pos - 1)
if curr == i:
ans += 1
return ans