An algorithm processes a finite, nonempty queue of expense claims. Its position starts at the first claim, and the queue does not change during processing. The instructions repeat while the position refers to a claim:
The requirement is to process every claim exactly once and then stop. Which revision meets that requirement, including when some claims have missing information?
Advance to the next claim after either outcome, then check whether another claim remains.
Advance by two positions after REVIEW, while advancing by one position after other outcomes.
End the entire loop whenever a claim receives REVIEW, leaving its recorded outcome in place.
Replace REVIEW with a default outcome, then restart the loop at the same current position.
Unlock full course notes by signing up
Tracking current and longest failure streaks
A payment gateway monitors consecutive validation failures. Its state consists of the values carried from one record to the next: the current failure streak and the longest failure streak seen so far.
Both values start at zero. For each record, the algorithm performs these updates in order:
If the result is Fail, increase the current streak by one. If the result is Pass, reset the current streak to zero.
Checking a shortcut against the full contract
A support system must select the request with the highest urgency score. If several requests share that score, it must select the one with the smallest request identifier. Scores are whole numbers, identifiers are unique positive integers, and records arrive in no guaranteed order.
The original algorithm keeps a candidate and checks every remaining record. It replaces the candidate when the new record has a higher score, or when scores are equal and the new record has a smaller identifier.
A proposed shortcut skips a record whenever its score is less than or equal to the current candidate's score, without checking its identifier. Which assessment is correct?
Designing tests for overlapping inventory rules
A retailer classifies inventory records using stock in whole units, supplier lead time in whole days, and a frozen-account flag. Stock is a nonnegative integer or missing; lead time is a positive integer or missing; the flag is always available.
The required policy is:
A missing stock or lead-time value produces REVIEW.
How arrival order changes comparison costs
A registration audit processes eight records. The client identifiers are 114, 208, 351 and 476, with each identifier appearing exactly twice. The records may arrive in any order.
For each incoming record, the algorithm scans all previously processed records from earliest to latest. Each equality check between two identifiers contributes one to the operation count, the total number of checks performed.
The scan stops at the first matching identifier or after checking every previous record. When a match is found, only the inner scan stops; processing continues with the remaining incoming records. After its scan, every incoming record is appended to the processed list, including duplicates. The first record requires no comparisons.