Most array solutions are built from a few small, reusable pieces. You'll write them so often that they should become automatic — like knowing your times tables. Here are the ones that matter most.
One pass, one or two variables. The only subtle part is the starting value: start max at the first element (or at -Infinity), never at 0 — an array of negative numbers would otherwise report 0 as its maximum.
Free account
Sign up to read the rest of this lesson: 5 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come