Find Max Number
Ever had a list of data and just needed to find the "peak" value? That’s exactly what Find Max Number is all about! You’re given an array of integers, and your mission is to identify the single largest numerical value hidden within that list. It sounds simple, but you’ll need to handle negatives, duplicates, and arrays of all sizes.
The "secret sauce" here is a Linear Scan. You start with a very small number (or the first element in the array) and walk through the list, comparing each value as you go. Think of it like a king-of-the-hill game: the current candidate stays on top until a bigger number comes along to take its place. This approach is incredibly efficient, running in O(n) time, ensuring you find the true peak data point within the provided array.
This is a fundamental skill for any data analysis task. Whether you''re finding the top score or the highest temperature, mastering this peak-finding logic is a basic building block for any developer.
Examples
Example 1: The maximum value in [1, 5, 3, 9, 2] is 9
Example 2: The maximum value in [-10, -5, -20, -1] is -1
Example 3: With a single element, that element is the maximum
Algorithm Flow

Best Answers
class Solution {
public int find_max_number(int[] nums) {
if (nums == null || nums.length == 0) return 0;
int max = nums[0];
for (int num : nums) {
if (num > max) max = num;
}
return max;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
