-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem1769.java
More file actions
34 lines (33 loc) · 963 Bytes
/
Problem1769.java
File metadata and controls
34 lines (33 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner;
public class Problem1769 {
// Minimum Number of Operation to Move All Balls to Each Box
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
String boxes=obj.nextLine();
int answer[]=new int[boxes.length()];
Solution1769 sc=new Solution1769();
answer=sc.minOperations(boxes);
for(int i=0;i<boxes.length();i++){
System.out.print(answer[i]+" ");
}
obj.close();
}
}
class Solution1769{
public int[] minOperations(String boxes){
int n=boxes.length();
int answer[]=new int[n];
for(int i=0;i<n;i++){
int count=0;
for(int j=0;j<n;j++){
if(i!=j){
if(boxes.charAt(j)=='1'){
count += Math.abs(i-j);
}
}
}
answer[i]=count;
}
return answer;
}
}