my code is not giving me min avg but just gives me 0.00 as answer i have tried using gpt but to no avail has it been fruitful
class Solution
{
public double minimumAverage(int[] nums)
{
double[] averages = new double [nums.length];
Arrays.sort(nums);
int startpos = 0;
int endpos = nums.length-1;
while (startpos<=endpos)
{
int[] subarray = Arrays.copyOfRange(nums,startpos,endpos + 1);
int min = Arrays.stream(subarray).min().getAsInt();
int max = Arrays.stream(subarray).max().getAsInt();
double average = (double) (min+max)/2.0;
averages[startpos] = average;
startpos++;
endpos--;
}
double avgMin = Arrays.stream(averages).min().getAsDouble();
return avgMin;
}
}
Note : The problem statement is LeetCode 3194;
my initial approach was basically sorting the array and then modifying start and end position ans respectively find avg min
New contributor
Krish Vij is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.