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.
A
'static
reference lasts for the entire duration of the program, even longer thanmain
, which makes sense because we've literally typed it into the source code, so the string will always be the same.The reason it's necessary is less intuitive, but important for understanding the rust lifetime system as a whole. When we return a reference, we're promising that something will actually be there, but when our function ends everything will be dropped! This is why solutions that return a
String
work,String
s are just fancy pointers, so we've allocated a place for ourString
and it will be dropped whenever the caller drops it.With that in mind, how come a
'static
reference actually works, what can it even be referencing? Well, it's a little bit tricky and actually references a string embedded in the program itself!Godbolt is really helpful here, you can literally see
"hello world"
here: https://godbolt.org/z/xGhWW6MbqIn the string version, though, it's nowhere to be found: https://godbolt.org/z/14vevMYco
In a nutshell, we use
'static
because it tells the compiler that the string lasts for the entire duration of the program, which is possible because it's embedded in the program, and is preferable because it lets us avoid a heavyString
for such a simple task.Why 'static? :)
This comment is hidden because it contains spoiler information about the solution
Wtf!
Can anyone explain this solution step by step? Seems too strange to me
This comment is hidden because it contains spoiler information about the solution
Well the code is readable, but the computational cost of it is way too big
This comment is hidden because it contains spoiler information about the solution
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.
why I get -2147483648 when running this for n=0?
I think this is the fastes solution
I think there might be a problem with the tests...