Very elegant method to generate and utilize created optimal scores from the left. This solution is very fast and nearly linear with size.
It is not close to linear. Richard, since he is using the function max for every number. It is at least O(n^2), in which n is size, and maybe even a little bit more since he is using indexing, another comparison(besides max), creating new arrays and so on. His code is small and functional though: kudos.
381 Solvers
201 Solvers
508 Solvers
Set the array elements whose value is 13 to 0
958 Solvers
Flip the vector from right to left
2841 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!