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.
This comment is hidden because it contains spoiler information about the solution