Leetcode 1491 Solution

This article provides solution to leetcode question 1491 (number-of-times-binary-string-is-prefix-aligned)

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