Totals = empty table
MaxRevenue = 0
For each bill X {
store = X.Store
If store has no total: Totals[store] = 0
Totals[store] = Totals[store] + X.BillAmount
if (Totals[store] > MaxRevenue) {
MaxRevenue = Totals[store]
}
}
Only the current store total changes. For nonnegative bill amounts, its total can only increase, so comparing that total against MaxRevenue maintains the best value in one pass. If negative refunds are allowed, a former leader can decrease; this shortcut needs rethinking rather than being applied blindly.
A has more bills and final revenue 105; B has one bill with amount 100. Average bills are 105/3 = 35 for A and 100 for B. “Best store” must be defined by a chosen metric.
Tutorial 2.4 sums LetterCount separately for every part of speech. This asks which category contributes the most letters, not simply the most word cards. From the supplied Words table, noun letters total 145, adjective letters 65, verb letters 35, preposition letters 27, article letters 18, pronoun letters 17, adverb letters 13 and conjunction letters 9.
Those category letter totals sum to 329, matching the whole paragraph. Nouns contribute the most letters. A category can be common but contain short words, so occurrence frequency and total letter contribution are distinct summaries.
Try it yourself
Three A bills are 20,30,40; one B bill is 100. Which wins by bill count and by revenue?
Show explained answer
A wins by count: 3 versus 1. B wins by revenue: 100 versus 90.
Try it yourself
A category has words of lengths 2,2,3. What are its frequency and letter contribution?
Show explained answer
Frequency=3 words; letter contribution=7 letters.
Try it yourself
Why is a running maximum of group totals straightforward for nonnegative bills?
Show explained answer
A group total never falls, so an existing maximum cannot be invalidated by a decrease. Only the changed total can improve it.
Try it yourself
Which part of speech contributes the most letters in Words.pdf?
Show explained answer
Noun, with a total LetterCount of 145. That is a sum of lengths, not a count of 145 words.
Source: Lecture 2.5; Tutorial 2.4. Small teaching datasets and diagrams are prepared for these notes; lecture and tutorial totals are identified explicitly.