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.
For the solution I focused in the amount of spaces that each container has and the amount of balls per type that there needs to be. Because at the end of the day what is asked is that each type of ball can be in one container.
the total capacity of a container is the sum of all the elements in the row
the total amount of balls per type is the sum of each i'th element in each row.
Then we would get, two lists, one that represents the amount of spaces that each container has, and the other one the amount of balls per type that we have. If we sort those lists and then check if they are equal, meaning that they have the same values on each position, is possible to swap the items between the containers and meet the requirements.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Organizing Containers of Balls
You are viewing a single comment's thread. Return to all comments →
For the solution I focused in the amount of spaces that each container has and the amount of balls per type that there needs to be. Because at the end of the day what is asked is that each type of ball can be in one container.
the total capacity of a container is the sum of all the elements in the row
the total amount of balls per type is the sum of each i'th element in each row.
Then we would get, two lists, one that represents the amount of spaces that each container has, and the other one the amount of balls per type that we have. If we sort those lists and then check if they are equal, meaning that they have the same values on each position, is possible to swap the items between the containers and meet the requirements.