package leetcode;

/**
 * https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/
 */
public class Problem1437 {
    public boolean kLengthApart(int[] nums, int k) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1437 prob = new Problem1437();
        System.out.println(prob.kLengthApart(new int[]{1,0,0,0,1,0,0,1}, 2)); // true
        System.out.println(prob.kLengthApart(new int[]{1,0,0,1,0,1}, 2)); // false
        System.out.println(prob.kLengthApart(new int[]{1,1,1,1,1}, 0)); // true
        System.out.println(prob.kLengthApart(new int[]{0,1,0,1}, 1)); // true
    }
}

@@ -196,313 +196,287 @@
     
-// TODO%0A        return false;
+int prevIdx = -1;%0A        for (int i = 0; i %3C nums.length; i++) %7B
 %0A    
-%7D%0A%0A
+   
     
-public static void main(String%5B%5D args) %7B%0A        Problem1437 prob = new Problem1437();%0A        System.out.println(prob.kLengthApart(new int%5B%5D%7B1,0,0,0,1,0,0,1%7D, 2)); // true%0A        System.out.println(prob.kLengthApart(new int%5B%5D%7B1,0,0,1,0,1%7D, 2)); //
+ if (prevIdx == -1 && nums%5Bi%5D == 1) %7B%0A                prevIdx = i;%0A            %7D else if (nums%5Bi%5D == 1) %7B%0A                if (Math.abs(i - prevIdx - 1) %3C k) %7B%0A                    return
  false
-%0A
+;%0A 
         
 Syst
@@ -475,157 +475,90 @@
     
-System.out.println(prob.kLengthApart(new int%5B%5D%7B1,1,1,1,1%7D, 0)); // true%0A        System.out.println(prob.kLengthApart(new int%5B%5D%7B0,1,0,1%7D, 1)); //
+       %7D%0A                prevIdx = i;%0A            %7D%0A        %7D%0A        return
  true
+;
 %0A   

Solve problem 1437