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.
It is considered bad coding practices to mutate an array or object in-place instead of creating a copy of it for further usage. One thing is that the original input is changed and if you want to debug your code based on the given input, it is not possible. The other thing is it will result in Undefined behaviour (UB) especially when the test setups, assertions and invoke callers are related to the input of your function, in which modifying it will cause other programs to read the incorrect initial or intermediate value.
This comment is hidden because it contains spoiler information about the solution
Your right, I hadn't seen the problem from that angle. So you mean it would be better to do something like the following one :
From a theoretical standpoint, looping once for the minimum and once for the maximum is equivalent to looping once and checking for maximum and minimum at the same time (time complexity).
While this version looks nicer, you're performing a comparison of 2 values, 2 times, for each entry in the array. Additionally, you're always rewriting the value in the local variables.
Perhaps it's better to simplify to 2 ifs, and only write when relevant.
indeed you can
Great. Thus, as you can see, you can much more simplify your algorithm :p
It was a homework assignment for an algorithms class I did a while back. I translated my answer from psudocode to java.
I don't understand why you need to iterate through all array elements so many times while you can just do something like that :