package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box/
 */
public class Problem1769 {
    public int[] minOperations(String boxes) {
        int[] answer = new int[boxes.length()];
        for (int i = 0; i < boxes.length(); i++) {
            int count = 0;
            for (int j = 0; j < boxes.length(); j++) {
                if (j == i || boxes.charAt(j) == '0') {
                    continue;
                }
                count += Math.abs(i - j);
            }
            answer[i] = count;
        }
        return answer;
    }

    public static void main(String[] args) {
        Problem1769 prob = new Problem1769();
        System.out.println(Arrays.toString(prob.minOperations("110"))); // [1,1,3]
        System.out.println(Arrays.toString(prob.minOperations("001011"))); // [11,8,5,4,3,4]
    }
}

@@ -34,17 +34,43 @@
 il.Array
-s
+List;%0Aimport java.util.List
 ;%0A%0A/**%0A 
@@ -287,16 +287,67 @@
 gth()%5D;%0A
+        List%3CInteger%3E indexes = new ArrayList%3C%3E();%0A
         
@@ -406,26 +406,93 @@
    i
-nt count = 0;%0A    
+f (boxes.charAt(i) == '1') %7B%0A                indexes.add(i);%0A            %7D%0A        %7D%0A
     
@@ -508,16 +508,16 @@
 int 
-j
+i
  = 0; 
-j
+i
  %3C b
@@ -535,15 +535,82 @@
 (); 
-j
+i
 ++) %7B%0A
+            int count = 0;%0A            for (int index : indexes) %7B%0A
     
@@ -625,17 +625,21 @@
     if (
-j
+index
  == i %7C%7C
@@ -652,17 +652,21 @@
 .charAt(
-j
+index
 ) == '0'
@@ -755,17 +755,21 @@
 abs(i - 
-j
+index
 );%0A     
@@ -850,281 +850,7 @@
    %7D
-%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1769 prob = new Problem1769();%0A        System.out.println(Arrays.toString(prob.minOperations(%22110%22))); // %5B1,1,3%5D%0A        System.out.println(Arrays.toString(prob.minOperations(%22001011%22))); // %5B11,8,5,4,3,4%5D%0A    %7D
 %0A%7D%0A

Solve prolbem 1769