Skip to content

Instantly share code, notes, and snippets.

@KodeSeeker
Created August 8, 2014 00:35
Show Gist options
  • Select an option

  • Save KodeSeeker/27aacc1464c19d403107 to your computer and use it in GitHub Desktop.

Select an option

Save KodeSeeker/27aacc1464c19d403107 to your computer and use it in GitHub Desktop.
Find the min average of an unsorted array in O( n ) time .
/**
Algorithm
Consider input
in =[3,2,1,0,13,1,1]
min_avg=0;
avg=0;
min_avg_so_far=0;
int i=0;
count =2;
while(i<arr.length)
{
sum=(arr[i]+arr[i++]);
avg=/2;
new_Avg=sum+arr[i]/(count++);
while(new_Avg<avg)
{
new_Avg
sum += arr[i];
i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment