Easy
Find the Maximum Element in an Array
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 15 min
- Arrays and Strings
Description
Given an array of integers, return the largest element.
The array contains at least one element. If the maximum value occurs more than once, return that value; its position does not matter.
For example, for [3, 1, 9, 2], the maximum element is 9.
Implement findMaximum(nums) to return the maximum integer in the array.
Constraints
1 <= nums.length <= 1000 -1000000 <= nums[i] <= 1000000
Sample cases
3Sample 1
Input
nums = [3,1,9,2]
Expected output
9
Sample 2
Input
nums = [-8,-3,-12]
Expected output
-3
Skills and languages
Concepts
- Control Flow and Data Types
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer