I think this is (so far) the most efficient solution for large m. It requires at most log(4*m)/log(5) iterations; while the smaller sized solutions that have been suggested require at least 0.8*m iterations (or a very large array). For example, for m = 10^5, this solution takes at most 8 iterations while the other solutions of smaller size require at least 80,000 iterations.
Return the largest number that is adjacent to a zero
3749 Solvers
Find the two most distant points
1628 Solvers
Find the maximum number of decimal places in a set of numbers
734 Solvers
965 Solvers
Sum of odd numbers in a matrix
311 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!