Ad
  • Custom User Avatar

    In a program like this where your code just needs to pass the test, performance is certainly not important. So why do I talk about performance here?
    First, the author of this solution himself is trying to optimize the solution by avoiding iterating over the array more than needed. But by doing so, he is actually introducing more overhead, so I want to discuss about that particular issue.
    Second, the point of this exercise is not just to learn a language, but to learn the methodology of programming also, which is why it's good to look at different approaches and see how you can write better code not JUST in Java, but in any language. I don't know your background, but if you have started working, you must have realized that nowadays programmers never solely use just one language. And even in one language, there are tons of libraries that you need to consider whether or not to use them when you design your application. Using high-level code? Sure! It's elegant. Unfortunately, that's not how life works.
    Finally, it's always good to think of how to optimize your solution. This is how most major tech companies screen people in their coding interview. They let you choose whatever language you like, does not mean everyone can choose Python and write 2 lines of code to pass the interview. In a high-level language, the fact that a feature is there does not mean you should always use it. Each feature is designed with a specific use case, and there are good and bad practices related to them. If you fail to consider that, you are not gonna go very far.
    By the way, bank applications prioritize security, not speed.

  • Custom User Avatar

    Are you understanding "not writing code like a compiler" as "you're authorized to write shit code with the worst time complexity ever just because you use high level functions"?? :o

    ofc not. ;)

    Performance is good, but the present people are talking about micro-optimizations, only. In most of the cases, those aren't needed. The complexity of the solution is good. Unless you're building a "bank application" or so, needing ultra-fast operations, it's pointless to optimize more than it's already.

  • Custom User Avatar

    I disagree with this: high level does not mean you can't try to optimize your algorithms. Efficiency may not be necessary for some purposes but this does not involve you should not try

    And you may write un-optimized code in any language, C included

    However, the answer is interesting because it indicates another way of coding

  • Custom User Avatar

    The main interest in using a high level language (well, is really java a "high level language"...? more than C or C++ for sure) IS to use high level functions so that you don't have to think like a compiler. That's supposed to be the job of the compiler, not yours.

    If you wanna have a superoptimized-ultraperformant code, don't even use Java, go directly for C.

  • Custom User Avatar

    It works but it is like using a mechanical shovel to plant a seed. So it is slow compared to more optimized solutions

  • Custom User Avatar

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