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 like this, simpler than my 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
it really should have a failing test on memory allocation with some IEnumberable the generates billions of values.
Reasons you may have been downvoted include:
This is a 7 kyu kata marked Fundamentals and Arrays; it is not marked for Optimization.
"Avoid premature optimization"; this code is very easy to understand and therefore should be very easy to maintain.
A good sorting algorithm will be O(n ln(n)) versus the O(n) of going through the list once. Yes, sorting is expected to take longer but is it significant?
I wrote a program that
(a) generates N random numbers,
(b) solves by a minimum selection method, and
(c) solves by sorting the array.
For N = 2,000,000 sorting the array was taking about 1/4 second (versus perhaps 30 ms for the other method). Unless I'm looking to run this a lot of times in an outer loop, that time isn't worth fussing over. AND, if I am running it many times I would first ask whether this is important for the overall program. If those 2,000,000 values are coming from a slow hard drive the program will appear slow with either algorithm.
If you're interested, at N = 20,000,000 the sorting took about 2 seconds (versus 80 ms). Here I would look at whether to optimize. Further, it took me a while to find my typo in the faster algorithm, which supports the maintainability aspect mentioned earlier.
aint no way💀
The second one was needed, as an error will be thrown without it
This comment is hidden because it contains spoiler information about the solution
duplicate issue (see @donaldsebleung's issue below)
You get used to them when you start using them.
This comment is hidden because it contains spoiler information about the solution
More code BUT definitely more optimal than 99% of the solutions here. Optimal is the way !!
Assuming that only one cell requires repositionion sort will take O(N)
This comment is hidden because it contains spoiler information about the solution
agree. but better than n*n
Loading more items...