Code Logo

Find Highest Score

Published at19 Apr 2026
Searching & Sorting Easy 9 views
Like0

Given an array of scores, find the highest score. Return the maximum value from the list. If the array is empty, return 0.

For example, the highest score from [45, 78, 92, 33, 67] is 92. From [100] it is 100. From [10, 20, 30] it is 30. An empty array returns 0.

Finding the maximum value is a mirror image of finding the minimum and is equally fundamental. The same linear scan pattern applies: initialize a candidate with a low sentinel value (or the first element), iterate through all elements, and update whenever a larger value is found.

This algorithm is the building block for more complex operations like finding the top K elements, computing the range (max - min), and normalizing data to a 0-1 scale. It appears in nearly every domain that processes collections of numerical data.

The solution iterates through the array keeping track of the largest value seen so far. If the current score exceeds the stored maximum, update it. After the loop, return the maximum. Time complexity is O(n), space complexity is O(1). Edge cases include an empty array (return 0), a single element (return it), and all equal scores (return that value).

Learn about our pseudocode specification
Guide

Example Input & Output

Example 1
Input
scores = [72, 88, 91, 84]
Output
91
Explanation

91 is the highest score in the list.

Example 2
Input
scores = [50]
Output
50
Explanation

With one score, that value is automatically the highest.

Example 3
Input
scores = []
Output
-1
Explanation

An empty list has no valid score to return.

Algorithm Flow

Recommendation Algorithm Flow for Find Highest Score

Solution Approach

Iterate through the list and track the highest score seen so far.

if list is empty then return 0
max = list[0]
for each score in list:
  if score > max then max = score
return max

First handle the empty list case by returning 0. Then initialize max to the first score. Loop through each remaining score; if the current score is larger than max, update max. After the loop, return max. This ensures the highest score is correctly identified regardless of its position in the list.

The algorithm is O(n) time with O(1) space. It is the mirror image of finding the minimum and uses the same linear scan pattern. This fundamental technique is the basis for more complex operations like finding the top K elements, computing statistical ranges, and normalizing data sets.

Best Answers

Pseudocode - Approach 1
program find_highest_score
dictionary
   scores: array[1..100] of integer
   highest, i, n: integer
algorithm
   input(scores)
   n <- scores.length
   if n = 0 then
      output(-1)
   else
      highest <- scores[0]
      for i <- 1 to n - 1 do
         if scores[i] > highest then
            highest <- scores[i]
         endif
      endfor
      output(highest)
   endif
endprogram