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.
Organizing Containers of Balls
Organizing Containers of Balls
Sort by
recency
|
624 Discussions
|
Please Login in order to post a comment
Solution in C#, first thing I did was realize that there is very little sorting necessary in this problem. What we have to do is find the sums of the x rows and the sums of the y columns. Once we've done that we sort both arrays and compare the arrays to ensure they match 1-to-1. If they do not, they are impossible to sort otherwise they are possible. I left my debugging code for brevity.
Essentially this swap sort method only works if each bucket has enough storage in it to hold the maximum count of a given item. (i.e. if there are two items of type A, there must be a corresponding bucket with two slots) this must be true for each item.
c++ solution:
here is my solution
for the love of god can you get into the habit of clarifying which indexes mean what in the input? every single problem on this site involving a matrix i have to comb through the example input to figure out which axes mean what because nobody bothered to clarify whether container[i][j] is the amount of i-color balls in container j or the amount of j-color balls in container i