Arrays and Hashing Array basics
47. Largest Element
Easy
You are given an array of integers nums. Return the largest value in it.
The answer is a value, not a position. If the largest value appears more than once, return that value.
Example 1
Input: nums = [12, 5, 31, 7, 31, -8]
Output:
31Explanation: 31 is the largest value. It appears twice, and the answer is the value, not a position.
Example 2
Input: nums = [-7, -3, -12]
Output:
-3Explanation: Every element is negative. The largest is the one closest to zero, −3.
Example 3
Input: nums = [42]
Output:
42Check your understanding
Work out the answer for this input before you write any code.
nums = [-5, -1, -9, -1]
Constraints
1 ≤ nums.length ≤ 105-109 ≤ nums[i] ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.