Skip to content

Commit 3bc3f8f

Browse files
Add files via upload
1 parent a8242e5 commit 3bc3f8f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Chocolatedistribute.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Arrays;
2+
3+
public class Chocolatedistribute {
4+
public int minchoco(int ch[],int a,int b){
5+
if(a==0 || b==0){
6+
return 0;
7+
}
8+
if(b>a){
9+
return -1;
10+
}
11+
Arrays.sort(ch);
12+
int min_diff=Integer.MAX_VALUE;
13+
for(int i=0;i<i+b-1;i++){
14+
int diff=ch[i+b-1]-ch[i];
15+
if(diff<min_diff)
16+
min_diff=diff;
17+
}
18+
return min_diff;
19+
20+
}
21+
public static void main(String[]args){
22+
int ch[]={1,8,45,8,174,23};
23+
int b=3;
24+
Chocolatedistribute choco=new Chocolatedistribute();
25+
System.out.println(choco.minchoco(ch,2,b));
26+
}
27+
}

0 commit comments

Comments
 (0)