Predict the output
What does this print?
from collections import Counter
jobs, gap = "AAABBC", 2
counts = Counter(jobs).values()
most = max(counts)
tied = sum(1 for c in counts if c == most)
print(max(len(jobs), (most - 1) * (gap + 1) + tied))Choose an answer, then open Show answer below to check it.
Show answer
Answer: A 7
Right: A _ _ A _ _ A needs 7 slots, and B and C fit into the gaps.
The busiest letter sets the frame, and the other jobs only add slots when the gaps are full.
Why not the others?
- B 6. A appears three times with two slots between each, which already needs 7.
- C 9. The last A needs no gap after it.