SECTION 08 / 24

Who belongs to all three topper lists?

1 min read
First intersect Maths and Physics to get [11,23]. Intersect that with Chemistry to get [11], Rahul.
First intersect Maths and Physics to get [11,23]. Intersect that with Chemistry to get [11], Rahul.
REAL COURSE DATA · BUILD AND UNPACK LISTS

Intersect the three topper lists

Follow one occurrence at a time. Choose another input to test empty lists, repeated IDs and different parameters.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next change, then step through the list. The original course records remain unchanged.

MathsPhysics = Intersect(MathsIDs, PhysicsIDs)
AllThree = Intersect(MathsPhysics, ChemistryIDs)
# MathsPhysics = [11,23]
# AllThree = [11]

The first scan compares 4 × 6 = 24 identifier pairs. The second compares 2 × 4 = 8. Together these membership scans use 32 comparisons after the lists are built. A full triple nested scan would inspect 4 × 6 × 4 = 96 triples. Preparation work to learn cutoffs and build lists is separate.

Only students present in both first lists can possibly be present in all three. Deepika (#23) passes Maths and Physics, but Chemistry 88 is below the 92 cutoff. Rahul (#11) has Maths 97, Physics 92 and Chemistry 92, so qualifies in every subject.

This is not the earlier three-prize selection rule. That rule began with eligibility in AT LEAST ONE subject and then ranked eligible totals. Here we ask for membership in ALL THREE subject collections. Neither result alone means “highest mark in every subject”: top-three distinct levels are broader than one maximum.

Try it yourself

Why can Deepika be removed after the second intersection?

Show explained answer

Her ID is absent from ChemistryIDs, so she fails the all-three condition even though she passes the first two subjects.

Try it yourself

Is Rahul necessarily the individual maximum in Chemistry?

Show explained answer

No. His Chemistry 92 is in its top three distinct levels; the Chemistry maximum is 97, achieved by Abirami.

Try it yourself

Why is the second intermediate list useful?

Show explained answer

It stores candidates already known to satisfy two conditions, so the next comparison need only process those candidates.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑