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.
definterQuartile(values,freqs):# Print your answer to 1 decimal place within this functionarr=[]foriinrange(len(values)):ans=[values[i]]*freqs[i]arr.extend(ans)arr.sort()n=len(arr)mid=n//2ifn%2==0:L=arr[:mid]U=arr[mid:]else:L=arr[:mid]U=arr[mid+1:]Q1=median(L)Q3=median(U)answer=Q3-Q1print(f"{answer:.1f}")defmedian(a):n=len(a)mid=n//2ifn%2==0:median=(a[mid]+a[~mid])/2else:median=a[mid]returnround(median)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 1: Interquartile Range
You are viewing a single comment's thread. Return to all comments →