HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /A diver's depths below the surface are stored as negative heights in metres: -12, -5, -30, -5, -8…
HardComputer ScienceHigh School (9–10)Computer Science › ProgrammingNumericalConceptualIGCSE

A diver's depths below the surface are stored as negative heights in metres: -12, -5, -30, -5, -8…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

A diver's depths below the surface are stored as negative heights in metres: −12-12−12, −5-5−5, −30-30−30, −5-5−5, −8-8−8 and −21-21−21. The program finds the highest one and its position.

pseudocode
DECLARE Heights : ARRAY[1:6] OF INTEGER
DECLARE Index : INTEGER
DECLARE Best : INTEGER
DECLARE BestIndex : INTEGER
// Heights[1] to Heights[6] are input first
FOR Index ← 1 TO 6
    INPUT Heights[Index]
NEXT Index
Best ← Heights[1]
BestIndex ← 1
FOR Index ← 2 TO 6
    IF Heights[Index] > Best
      THEN
        Best ← Heights[Index]
        BestIndex ← Index
    ENDIF
NEXT Index
OUTPUT Best, " at position ", BestIndex

What is output? A student starts Best at 0 instead of Heights[1]. What would that version output, and why is it wrong?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

DECLARE Name : ARRAY[Lower:Upper] OF TYPE makes a fixed-length array of one data type. An element is Name[Index], and the index may be a variable or an expression. A FOR loop from the lower bound to the upper bound visits every element. Pseudocode arrays usually start at 1; Python lists at 0.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Step 1. The correct program. Best starts as −12-12−12 at position 1. −5-5−5 at position 2 is greater, so Best becomes −5-5−5 at position 2. The other −5-5−5, at position 4, is not greater, so position 2 stays. The output is -5 at position 2.

Step 2. The faulty version. With Best ← 0, no height is greater than 0, so Best stays 0 and BestIndex stays 1. The output would be 0 at position 1, but 0 is not one of the heights.

Answer: −5-5−5 at position 2. The faulty version gives 0, a value not in the array.

Watch out. Start the largest and the smallest at the first element, never at a number you guessed.

Log in to save this for later
← All Problems
← Follow the program. What values does the array hold, and what are the two outputs?A program tries to move everyone in a queue back one place, to make room at the front… →
More onComputer Science › Programming

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. One-dimensional arraysArrays and Files in Pseudocode

More on this topic

  1. A long scenario question. A teacher has the names of 5 students in the file Names.txt, one name a…Hard
  2. Shopping.txt holds six lines: bread, rice, milk, eggs, tea and jam…Medium
  3. The file Best.txt holds one line: 120. What is output, and what does Best.txt hold afterwards, when…Easy
The nine squares of a board are input row by row: X, O, O, then X, X, X, then O, a dot for an empty…Hard
  • Three teams play three games each. Points[Team, Game] holds the points of a team in a game…Medium
  • All problems on this topic →