nums. You may assume the array always has at least one element.Largest Element
L1 Easy Arrays & Hashing
Concept
To find the biggest value in a list, keep a running champion and update it whenever a new value beats it.
Return the single largest integer in
Examples
▸ nums = [3, 9, 2, 7]
→ 9
▸ nums = [-1, -5, -2]
→ -1
▸ nums = [7]
→ 7
Progressive Hints
Hint 1 · Nudge
You only need to remember one number the whole way through.
Hint 2 · Plan
Assume the first element is the largest. Compare it with each following element and keep whichever is bigger. Return the survivor.
Hint 3 · Approach
best = nums[0]. For each remaining n: if n > best then best = n. Return best.
All hints are out. Take a breath and give it a shot.
Output
// Run your code to see the output here.