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.
deftoys(mylist):weights=sorted(list(set(mylist)))# The smallest element will be the first pivotcur=weights[0]containerCount=int(len(weights)>0)# Time: O(n) as we are iterating over each element of the collection# Space: O(n) as we are storing a sorted set list of similar size as inputforeleminweights:ifelem>cur+4:containerCount+=1cur=elem#UpdatethepivotreturncontainerCount
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Priyanka and Toys
You are viewing a single comment's thread. Return to all comments →