Leetcode Problem 1437. Check If All 1's Are at Least Length K Places Away

1437. Check If All 1's Are at Least Length K Places Away

Leetcode Solutions

One Pass + Count

  1. Initialize a counter count to k to handle the case when the first element is 1.
  2. Iterate over each element in the array nums.
  3. If the current element is 1: a. Check if count is less than k. If so, return false. b. Reset count to 0.
  4. If the current element is 0, increment count.
  5. After the loop, return true as all 1s are at least k places apart.
UML Thumbnail

Bit Manipulation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...