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.
hello!
basically follow the above code which sorts the toys. here i am taking advantage of the fact that all values lie between 1 and 10^5. so make an array of that length and let index i represent the number of toys of weight i. this is called count sort which is O(n). then iterate from start and see if u hit a toy (count > 0). if so, increment counter by 4 since next 4 weights will be free.
Priyanka and Toys
You are viewing a single comment's thread. Return to all comments →
hello! basically follow the above code which sorts the toys. here i am taking advantage of the fact that all values lie between 1 and 10^5. so make an array of that length and let index i represent the number of toys of weight i. this is called count sort which is O(n). then iterate from start and see if u hit a toy (count > 0). if so, increment counter by 4 since next 4 weights will be free.