Find the Largest Element in an Array
Given a non-empty array of integers arr, return its largest value. The result is the value, not its index. Duplicate copies of the maximum do not change the…
Given a non-empty array of integers `arr`, return its largest value. The result is the value, not its index. Duplicate copies of the maximum do not change the result.
- `1 <= arr.length <= 10^5` - `-10^9 <= arr[i] <= 10^9` - Array has at least one element. - The interactive visualizer accepts at most 12 values; longer valid arrays are execution-only.
Example 1: input arr = [5, 2, 8, 1]; output 8. A left-to-right scan finds 8 as the highest value.
Example 2: input arr = [14, 3, 27, 9, 11]; output 27. 27 is encountered midway through the scan and is never surpassed.
Example 3: input arr = [-6, -2, -9, -4]; output -2. All values are negative; -2 is the least negative and therefore the largest.
Category: Arrays & Hashing. Topic: arrays. Difficulty: Easy. Patterns: linear-scan, sorting.