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.
guys look PLEASE... this solution is straight up NON-PRACTICAL in the context of real programming... Readability is ALWAYS secondary to such a order of magnitude difference in speed... in the context of "real" programming there is no question of it... the difference between O(n) and O(n**2) is as stark as taking your money and literally burn it or invest it smartly... Please if you're a newbie and don't know whats going on, learn about time and space complexity asap. I made the same mistake earlier for sure but learning some of the basics totally changed how i look at coding.
"Good enough is perfect" is often a recipe for tech debt. While I will agree that perfect is the enemy of good, your argument that this is a best practice is flawed. This is a solution that works. It is not a best practice.
I would pick O(n^2) over O(n) if it's code that is A) quick to produce, B) readable and quickly understandable by those who will maintain it, and C) isn't running in "hot" code that's being called 100x per second.
While calculating the sum of the entire array and then shifting values from one side to the other is undeniably more computationally efficient, it's probably not your first instinct when presented this problem and will probably take you longer to get working. This is especially true with code that's more complex than this example.
IMO, good enough is perfect, until it's not good enough anymore. Once it's proven to be your biggest problem, then you can optimize it.
For those reasons, I would argue that this is best practice code. I would not argue that it's clever.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
From a readability perspective, I like this solution. It maps to the question very well.
Yes - it's not very optimal, but I'd rather pick maintanable code over anything else.
This comment is hidden because it contains spoiler information about the solution