Search for a command to run...
You are given an array of integers. Your task is to find and return the maximum (largest) element present in the array.
The array may contain positive numbers, negative numbers, or a mix of both. You need to efficiently traverse the array and determine the highest value among all elements.
Input Format:
The first line contains an integer n — the number of elements in the array.
The second line contains n space-separated integers.
Output Format:
Print a single integer — the maximum element in the array.
Constraints:
1≤n≤1051 \leq n \leq 10^51≤n≤105
−109≤arr[i]≤109-10^9 \leq arr[i] \leq 10^9−109≤arr[i]≤109
Example: Input: 5 1 3 7 2 5
Output: 7
Explanation: Among all elements in the array, 7 is the largest, so it is the output.
Hint: Initialize a variable with the first element and iterate through the array, updating it whenever a larger element is found.
Example 1
[3,1,8,4,5]8Example 2
[-5,-1,-10]-1[3,1,8,4,5]
8