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.
While this has many up-votes for best practices, it's worth noting that searching the entire list of queues for every single customer results in a worst case time complexity of
O(nm)
, wheren
is the number of queues andm
is the number of customers. You can achieveO(n log m)
using Python'sheapq
module.Oh my God.
As several people have upvoted this as best practice, it's important to provide the counterpoint.
This solution is
O(4n)
when it's trivial to write anO(n)
solution that's easier to understand.This code is convoluted for what can be an easy to understand set of if statements in approximately the same number of LOC.
Note that this has time complexity O(N^2) while it's possible to achieve O(N).
This handles punctuation
This comment is hidden because it contains spoiler information about the solution
You're right: most solutions here are O(n^2), but this one is O(n). The code duplication makes it read like a C program, so initially I was surprised.
It doesn't modify the arrays, but creates a new array.
Just a tip: comments should explain what is not obvious from the code, otherwise they end up being a burden.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution