SECTION 09 / 15

Call one maximum procedure four times

2 min read
On this page 1 headings

We want to know whether some student achieves the maximum in every subject. Finding the maximum four times is the same task with a different field each time. This is a good use for a parameterized procedure.

Subject maxima sum to 286, while the largest real student total is 281.
Subject maxima sum to 286, while the largest real student total is 281.
MaxMaths = MaxMarks(Scores, "Mathematics")
MaxPhysics = MaxMarks(Scores, "Physics")
MaxChemistry = MaxMarks(Scores, "Chemistry")
MaxTotal = MaxMarks(Scores, "Total")
SubjectMaxSum = MaxMaths + MaxPhysics + MaxChemistry
HasCommonTopper = (MaxTotal == SubjectMaxSum)
REAL COURSE DATA · FOLLOW THE PROCEDURE

Call MaxMarks four times

Read the current record, check the explanation, and watch the variables. Use Back to revisit any step.

Ready

CURRENT RECORD

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Start at the first step. Watch the current row and the values we remember.

Why the comparison works

Every student’s Mathematics mark is at most 97, Physics at most 92, and Chemistry at most 97. So no total can exceed 286. To reach 286, a student must reach every one of those subject maxima: a deficit in one subject cannot be cancelled by exceeding another maximum.

The actual largest total is 281, earned by Rahul with 97,92,92. His Chemistry mark is five below the Chemistry maximum 97, which explains the gap 286−281=5. Nobody achieves all subject maxima in these cards.

Procedure MaxMarks(Rows, Field)
    if (Rows is empty) { report "No maximum"; stop }
    Best = first row[Field]
    for each remaining row X in Rows {
        if (X[Field] > Best) { Best = X[Field] }
    }
    return Best
End Procedure

HasCommonTopper means at least one student reaches every maximum. It does not establish that the student is unique. Check that Total equals the sum of the three subjects before using this reasoning.

Try it yourself

What is the sum of subject maxima?

Show explained answer

97+92+97=286.

Try it yourself

Is 286 an actual student total?

Show explained answer

No. It is an upper bound assembled from potentially different students.

Try it yourself

What does equality of MaxTotal and SubjectMaxSum establish?

Show explained answer

At least one student reaches all subject maxima, assuming totals are consistent.

Try it yourself

Why store each procedure result in a separate variable?

Show explained answer

Later calls return new answers. Saved variables keep all four values available for the final comparison.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑