From d1ca17222c6841d4af9f6236209aec2cc9a40240 Mon Sep 17 00:00:00 2001 From: chayan das Date: Mon, 17 Nov 2025 11:59:57 +0530 Subject: [PATCH] Create 1437. Check If All 1's Are at Least Length K Places Away --- ...k If All 1's Are at Least Length K Places Away | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 1437. Check If All 1's Are at Least Length K Places Away diff --git a/1437. Check If All 1's Are at Least Length K Places Away b/1437. Check If All 1's Are at Least Length K Places Away new file mode 100644 index 0000000..a1734bf --- /dev/null +++ b/1437. Check If All 1's Are at Least Length K Places Away @@ -0,0 +1,15 @@ +class Solution { +public: + bool kLengthApart(vector& nums, int k) { + int prev = -1; + + for(int i = 0; i < nums.size(); i++){ + if(nums[i] == 1){ + if(prev != -1 && i - prev - 1 < k) + return false; + prev = i; + } + } + return true; + } +};