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(w):count=0w.sort()N=len(w)i=0whilei<N:# The weight of the current toy.current_toy_weight=w[i]# We need at least one container, so we increment the count.count+=1# We can fit any toy with a weight up to 4 units greater than the first toy in the container.limit=current_toy_weight+4# We find how many toys fit in this container.whilei<Nandw[i]<=limit:i+=1returncount
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 →