Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I have tried something similar (but less elegant), however this algorithm does not pass the test with the dataset:
customers {100, 90, 90, 60, 50}
n 2
this algorithm return 210 (100+60+50 = 210 vs 90 + 90 =180)
but true result: 200 (100 + 90 = 190 vs 90 + 60 + 50 = 200)
correct me, if i am wrong. This solution takes n^2 running time due to for each customer, this program is finding the register by checking each register's least. Space-wise, it is O(n) where the n is the number of registers.
There are specifications:
So a (silly and absurd) input of a negative queue will never happen.
Very nice! However, it will crash when (n <= 0).
it is so beautiful and I am superised that my code is similar to this solusion ,I'm just a noob guy here XD
For those unfamiliar, the problem is also known as "Bin Packing". I was very suprised but the simplicity of solution, when I first heard about it as well :D
If you have 20 customers and 1 guy - iterations of outer and inner are 20.
if you have 5 customers and 100 guys - iterations of outer and inner are 500.
So simply O(customers.size() * n).
The thing you have to note here is that n is "int", so the solution is more than acceptable.
This is obviously a very elegant solution but wouldn't this be O(n^2)?
4 lines? kill myself
I just want to comment on the fact that I gasped audibly when I understood what you were doing here. Very elegant and simple solution to the problem.
I really like this solution.
Shows me that I included one too many steps, utilising min_element AND distance to retrieve the index of the next smallest element.
how to take 16 lines of code and turn it into 5 ;)
very well done, nice to see how smooth it can be.
also best/fastest solution due to use of min/max ^^
beautiful codes!
I think I get it. Thank you
The idea is to "simulate" all the rows with an easy method: just take the numbers of customers and add to the queue with the lowest value. Then you return the highest value queue.
in detail: first we create another vector of values of fixed size (n) and set the values to 0.
then we iterate all the customers values (int i : customers) where i is getting the value of customers[0],[1]...etc; and we add that value to de lowest value queue.
at the end we got a vector of n values (queues) and we just have to return the max value of them.
Loading more items...