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
Hey @mildlyeastern,
That's a great question! It's referred to as a ternary. It's a one line conditional statement where the condition is followed the truthy evaluation followed by the else. So like this:
condition == true ? ifConditionWasTrue : elseIfItWasNot
aka
if (condition == true) {
return ifConditionWasTrue;
}else{
return elseIfItWasNot
}
Can someone explain to me what the ? and the : does in the return statement.
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.