Leetcode 1548 Solution
This article provides solution to leetcode question 1548 (check-if-all-1s-are-at-least-length-k-places-away)
Access this page by simply typing in "lcs 1548" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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