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.
This question is misleading!
When I test my code below to equate all numbers in the list and count number of operations, I get the minimum number of operations compared to the ones gotten on their test cases, so my code does not pass their test cases!
defequal(arr):# Write your code herecount=0whilemax(arr)!=min(arr):mx=max(arr)mn=min(arr)diff=mx-mnaddValue=5if2<=diff<5:addValue=2ifdiff==1:addValue=1numberOfMx=arr.count(mx)arr=[a+addValueforainarrifa!=mx]+[mxfornuminrange(numberOfMx)]count+=1print("Final arr:",arr)print("Length of arr:",len(arr))returncount
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
This question is misleading! When I test my code below to equate all numbers in the list and count number of operations, I get the minimum number of operations compared to the ones gotten on their test cases, so my code does not pass their test cases!