Ad
  • Default User Avatar

    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.

  • Custom User Avatar

    "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.

  • Default User Avatar

    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.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    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.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution