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.
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.
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.
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
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.
It works but it is like using a mechanical shovel to plant a seed. So it is slow compared to more optimized solutions
I don't understand your explanation for array {1,2,3,4,5,6} since the {1,100,50,-51,1,1} array has a solution with index 1. What is the difference between these arrays ?