2021-10-12
Eight before nine in a list.
Warmup: count the number of times that an 8 comes before a 9 in a list of integers.
-
Basic: count one for every 8 that comes immediately before a 9.
-
Advanced: count one for every time there is a 9 somewhere after an 8, giving two for this example:
[8,1,1,1,9,8,9]
Class notes
If the problem is phrased “count the number of times a 9 comes after an 8”, then I would count two for either of these examples:
[8,9,9]
[8,8,9,8,9]