Ready to begin
No records have been processed. Start with Next step.
![First intersect Maths and Physics to get [11,23]. Intersect that with Chemistry to get [11], Rahul.](/images/computational-thinking/week-5/all-three.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.
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.
Why can Deepika be removed after the second intersection?
Her ID is absent from ChemistryIDs, so she fails the all-three condition even though she passes the first two subjects.
Is Rahul necessarily the individual maximum in Chemistry?
No. His Chemistry 92 is in its top three distinct levels; the Chemistry maximum is 97, achieved by Abirami.
Why is the second intermediate list useful?
It stores candidates already known to satisfy two conditions, so the next comparison need only process those candidates.