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
AI Mock Interview
Leetcode Solutions
One Pass + Count
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize a counter
count
to
k
to handle the case when the first element is
1
.
Iterate over each element in the array
nums
.
If the current element is
1
: a. Check if
count
is less than
k
. If so, return
false
. b. Reset
count
to
0
.
If the current element is
0
, increment
count
.
After the loop, return
true
as all
1
s are at least
k
places apart.
Bit Manipulation
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...