Largest Element

Arrays Fundamentals Easy
  • This problem's foundational concept is frequently used in data analysis software and algorithms
  • For example, finding the largest or maximum value in a data set is commonly needed in statistical computations, such as when calculating the range (the difference between the highest and lowest values) or understanding the distribution of data
  • Furthermore, in real-time systems or applications like weather forecasting and stock market analysis, determining the highest value is crucial to predict potential peaks

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