Find the Missing Step in a Sequence
Scenario
A campus library checkout kiosk checks whether a book has copies left and hands it to a student, but a technician compares two versions of the kiosk flowchart: Version A forgets to decrease availableCopies after checkout, while Version B updates availableCopies before finishing.
Try it yourself
If 1 copy of a book remains and two students check it out one after another using Version A, what will the second student see?
| Case | Result |
|---|---|
| availableCopies = 3; Version A (no update) vs Version B (update -1) after 1 checkout | Select a choice above to see what happens. |
| availableCopies = 1; two back-to-back checkouts on Version A vs Version B | Select a choice above to see what happens. |
| availableCopies not read before checking availableCopies > 0 (uses stale cached 2 when shelf has 0); Version B reads current count first | Select a choice above to see what happens. |
Reveal the explanation
- availableCopies = 3; Version A (no update) vs Version B (update -1) after 1 checkout
Version A still shows 3; Version B shows 2
- availableCopies = 1; two back-to-back checkouts on Version A vs Version B
Version A approves both (invalid double checkout); Version B approves first (0 left) and blocks second
- availableCopies not read before checking availableCopies > 0 (uses stale cached 2 when shelf has 0); Version B reads current count first
Version A tries to lend a missing book; Version B reads 0 and stops
To audit any sequence, trace each piece of data from start to finish: confirm it is read fresh before being tested, and confirm every completed action writes its updated value back before the sequence ends.
Download shared test cases
Your turn
Compare a 4-step study-room booking sequence (1. Read roomStatus, 2. Confirm roomStatus is free, 3. Print ticket, 4. End) against what happens when two students book the same room, and write down the exact missing step and where it belongs.
Common mistake Adding a second check instead of adding the missing state update (writing roomStatus = booked).
Check your work
Identify Step 3.5 as 'Set roomStatus = booked' placed immediately before printing the ticket or ending the sequence.
Quick check
This browser could not save your progress. Changes last until you leave the page.