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.
Here's a solution in Python that is O(max(N, max(W))) in time, and is space efficient
def toys(w):
w = {weight: True for weight in w}
containers = 0
max_w = max(w)
i = 0
while i <= max_w:
if w.get(i):
containers += 1
i += 4
i += 1
return containers
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 →
Here's a solution in Python that is O(max(N, max(W))) in time, and is space efficient