Largest Element

Arrays Fundamentals Easy

Given an array of integers nums, return the value of the largest element in the array

Examples:

Input: nums = [3, 3, 6, 1]

Output: 6

Explanation: The largest element in array is 6

Input: nums = [3, 3, 0, 99, -40]

Output: 99

Explanation: The largest element in array is 99

Input: nums = [-4, -3, 0, 1, -8]

Constraints

  • 1 <= nums.length <= 105
  • -104 <= nums[i] <= 104
  • nums may contain duplicate elements.

Hints

  • Start by assuming the first element is the largest, then iterate through the array to compare each element with the current largest.
  • Use a single loop to traverse the array and update the largest element whenever a larger value is found.

Company Tags

Mastercard Unity Technologies Nutanix Electronic Arts Etsy Cloudflare Bain & Company Bloomberg Square Johnson & Johnson Seagate Technology Oracle Intel Docker Salesforce American Express Robinhood Epic Games Reddit IBM Lyft Boston Consulting Group McKinsey & Company Target Philips Healthcare TCS Cognizant Accenture Infosys Capgemini Wipro