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

Check If All 1's Are at Least Length K Places Away Problem — ExecCode Easy DSA Practice

Solve the Check If All 1's Are at Least Length K Places Away problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an binary array nums and an integer k, return true if all 1 's are at least k places away from each other, otherwise return false.

Examples

Input {"nums": [1, 0, 0, 0, 1, 0, 0, 1], "k": 2}; Output True. Input {"nums": [1, 0, 0, 1, 0, 1], "k": 2}; Output False

Constraints

1 <= nums.length <= 10^5 0 <= k <= nums.length nums[i] is 0 or 1

Practice Check If All 1's Are at Least Length K Places Away free on ExecCode. Browse DSA problems, topic map, and placement guides.