Step 3: Solve Problems on Arrays [Easy -> Medium -> Hard]›Easy
Largest Element & The Crown Holder
EasyFunction: largestElement()
ASCI Mission Breakdown • Simple as Hell
"Find and return the single largest value inside an array of numbers."
Real-World Metaphor:
Imagine an audition line. The first person in line puts on the crown. Whenever someone taller or higher-scoring walks past, the crown is handed over to them. Once everyone has walked past, the crowned person is the definitive champion.
Interactive Visual WalkthroughARRAY-POINTERS
Step 1 / 3
Contestants: [2, 5, 1, 3, 0]
Crown
2
[0]
5
[1]
1
[2]
3
[3]
0
[4]
Memory Notepad / State Tracker
Current Max:2
Evaluating
1. Crown the First Element
Start with max = nums[0] = 2. Person at index 0 holds the crown.
How to Think About This (Mental Model)
Initialize max = nums[0] (give the crown to the first person).
Walk through the rest of the array from index 1 to the end.
If nums[i] > max, update max = nums[i] (pass the crown).
After checking everyone, return max.
### The Mission
Imagine a lineup of contestants standing in a row, each holding a card with a number on it.
You are holding the **Winner's Crown**. Your mission is to walk down the row from left to right and make sure that by the time you reach the end, the crown is held by whoever had the single highest number!
Examples
Example 1
Input: nums = [2,5,1,3,0]
Output: 5
Explanation: 5 is the maximum element in the array.
Example 2
Input: nums = [8,10,5,7,9]
Output: 10
Explanation: 10 is the maximum element.
Constraints
1 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9
Topic Tags:
Solve Problems on Arrays [Easy -> Medium -> Hard]EasylargestElement