Code Logo

Find Maximum Value

Published at19 Apr 2026
Searching & Sorting Easy 5 views
Like0

Imagine you have a big pile of numbers and you need to pick out the absolute largest one. In Find Maximum Value, your task is to look through an array and determine which value stands above the rest.

The key here is comparison. You will need to step through the list one by one, keeping track of the biggest number you’ve seen so far. If you encounter a new number that’s even larger, that becomes your new "maximum" to remember.

For instance, if you have [1, 5, 3], you would check 1, then see 5 and realize it is bigger, then see 3 and ignore it because 5 is still the king. By the end of the list, you should be able to tell everyone that 5 is the highest value in the bunch.

Learn about our pseudocode specification
Guide

Algorithm Flow

Recommendation Algorithm Flow for Find Maximum Value
Recommendation Algorithm Flow for Find Maximum Value

Solution Approach

Finding the maximum value in a list requires a linear scan while keeping track of the largest element encountered so far.

max_val <- arr[1]
for i <- 2 to n do
   if arr[i] > max_val then
      max_val <- arr[i]
   endif
endfor
output(max_val)

We initialize max_val with the first element of the array. Then, we loop through the rest of the array. For each element, we compare it with our current max_val. If the new element is larger, it becomes the new maximum. This approach ensures that we find the global maximum in O(n) time.

Best Answers

Pseudocode - Approach 1
program find_max
dictionary
   n, i, max_val: integer
   arr: array[1..100] of integer
algorithm
   input(n)
   for i <- 1 to n do
      input(arr[i])
   endfor
   max_val <- arr[1]
   for i <- 2 to n do
      if arr[i] > max_val then
         max_val <- arr[i]
      endif
   endfor
   output(max_val)
endprogram