We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Enter your code here. Read input from STDIN. Print output to STDOUTa=int(input())numbers=list(map(int,input().split(" ")))numbers.sort();maxq=1currentMax=1flag=0mode=numbers[0]mean=sum(numbers)/aifa%2==0:median=(numbers[a//2]+numbers[(a//2)-1])/2else:median=numbers[(a//2)+1]foriinrange(1,len(numbers)-1):if(numbers[i]==numbers[i-1]):maxq=maxq+1ifmaxq>currentMax:mode=numbers[i]flag=1else:ifflag==1:currentMax=maxqflag=0maxq=1print(mean)print(median)print(mode)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 0: Mean, Median, and Mode
You are viewing a single comment's thread. Return to all comments →