In my code, I get an output of an array but it displays some unwanted zeros after getting the array, Can you explain a way to avoid getting these unwanted zeros.
static int[] cutTheSticks(int[] arr) {
int min,i,j,count=0;
int []arr2=Arrays.copyOf(arr,arr.length);
int []temp =Arrays.copyOf(arr,arr.length);
for(i=0;i<arr.length;i++){
Arrays.sort(arr2);
min= arr2[0];
for(j=0;j<arr.length;j++){
if(temp[j]>0){
count++;
}
temp[j]=temp[j]-min;
}
int []res = new int [arr.length];
while(count!=0) {
res[i] = count;
count = 0;
}
return res;
}