implement getMedian to return the maximum of the array in CS
implement getMedian to return the maximum of the array in C
Solution
It is not recommended to calculate max of an array using getMedian. Because if we do that the time complexity will be higher by that procedure. Because to calculate median we need to sort the array which take n log(n) time. The code given below will do the job in O(n) time.
#include<stdio.h>
#include<conio.h>
int main ()
{
int arr[5]={4, 3, 8, 6,1};
length=sizeof(arr);
int max=0;
for(int i=0; i<n; i++)
{
if(max<arr[i])
max=arr[i];
}
return max;
}
