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.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'quartiles' function below.## The function is expected to return an INTEGER_ARRAY.# The function accepts INTEGER_ARRAY arr as parameter.#defmedian(q):ifisinstance(q,int):returnqn=len(q)ifn%2==0:return(q[n//2-1]+q[n//2])/2else:returnq[n//2]defquartiles(arr):arr.sort()n=len(arr)m1=0m2=0m3=0m1=median(arr[0:n//2])ifn%2==0:m3=median(arr[n//2:n])m2=median(arr)else:m3=median(arr[(n//2)+1:n])m2=median(arr[n//2])returnint(m1),int(m2),int(m3)if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')n=int(input().strip())data=list(map(int,input().rstrip().split()))res=quartiles(data)fptr.write('\n'.join(map(str,res)))fptr.write('\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 1: Quartiles
You are viewing a single comment's thread. Return to all comments →