Trains the technique from
LeetCode 1437Check If All 1's Are at Least Length K Places AwayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A track is logged as nums, where 1 marks a sleeper due for replacement and 0 one that is not.
Return true when every two marked sleepers have at least k unmarked sleepers between them, and false otherwise. A track with fewer than two marked sleepers always qualifies.
Example 1
The first pair of marks has three unmarked sleepers between them and the second pair has two, so both reach the required two.
Example 2
The two marks have a single unmarked sleeper between them, which falls short of the required two.
Example 3
There is only one marked sleeper, so there is no pair to be too close.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def spacing_holds(nums: list[int], k: int) -> bool:public boolean spacingHolds(int[] nums, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.