Leetcode 1548 Solution

This article provides solution to leetcode question 1548 (check-if-all-1s-are-at-least-length-k-places-away)

https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away

Solution

class Solution:
    def kLengthApart(self, nums: List[int], k: int) -> bool:
        last_one_pos = -sys.maxsize

        for i, num in enumerate(nums):
            if num == 1:
                if i - last_one_pos <= k:
                    return False
                last_one_pos = i
        return True