Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.
Draw a loop that checks each of the 30 elements, with a counter for the number output:
START → Set Index to 1 and Count to 0 → decision "Is Index = 31?"
If NO: decision "Is Data[Index] = ""?" If YES (blank): Set Index to Index + 1 and go back. If NO: Set Count to Count + 1 → Output Data[Index] → Set Index to Index + 1 → back to the first decision.
If YES: Output Count → END.
Index and Count both set before the loop [1]
Loop that goes through exactly 30 elements [1]
Test for an empty string (or a non-empty one) in the current element [1]
Count increased when the element is not blank, inside the loop [1]
Both outputs (each non-blank element in the loop, and Count after it) under the correct conditions [1]
Testing for the empty string first is also accepted.
▶ Whole paper
Video solution of the whole paper · by CSFeedbySirNisarAli. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.