Ready to begin
No records have been processed. Start with Next step.
![Physics maximum 92 belongs to IDs [5,7,11,18]. A new larger maximum resets the candidate list; an equal maximum extends it.](/images/computational-thinking/week-5/tied-maxima.png)
Follow one occurrence at a time. Choose another input to test empty lists, repeated IDs and different parameters.
Ready
No records have been processed. Start with Next step.
Predict the next change, then step through the list. The original course records remain unchanged.
Max = empty
TopperIDs = []
foreach Pair in Pairs:
ID = first(Pair)
Mark = last(Pair)
if Max is empty OR Mark > Max:
Max = Mark
TopperIDs = [ID]
else if Mark == Max:
TopperIDs = TopperIDs ++ [ID]
return (Max, TopperIDs)When a larger mark arrives, earlier candidates are no longer maximum scorers: replace their list with [ID]. When an equal mark arrives, keep earlier tied IDs and append this one. When a smaller mark arrives, change neither variable. The updates must keep the maximum value and its owner list consistent.
The real Physics result is maximum 92 with IDs [5,7,11,18]: Akshaya, Aditya, Rahul and Abirami. Maths maximum 97 has [11,23]. Chemistry maximum 97 has [18]. These are maximum owners, not top-three-level lists.
An empty-input contract can return an unavailable maximum and an empty owner list. Do not report 0 as a witnessed maximum of an empty list. For known non-negative, non-empty marks a zero sentinel can work for the value, but a clear empty state handles the owner list more reliably.
Why not simply append every student who ever set a running record?
Some running records are later beaten. Reset the ID list when a strictly larger mark appears.
What happens when the next Physics mark is also 92?
Append that student’s ID while keeping Max = 92.
Can three independent IFs accidentally append the new record holder twice?
Yes, if setting Max makes a later equality IF true in the same iteration. Use IF…ELSE IF for these mutually exclusive update cases.