ProgrammingVery hardTCS NQT · Accenture

Count how many copies of the word BALLOON can be formed from the letters of "lloolldnaubbalo" (each letter used at most once per copy). BALLOON needs b 1, a 1, l 2, o 2, n 1. The answer is the minimum over the letters of available count divided by needed count (integer division). What is printed?

Count how many copies of the word BALLOON can be formed from the letters of "lloolldnaubbalo" (each letter used at most once per copy). BALLOON needs b 1, a 1, l 2, o 2, n 1. The answer is the minimum over the letters of available count divided by needed count (integer division). What is printed?
count letters of the string
Print min(b, a, l div 2, o div 2, n)
  1. A. 1
  2. B. 2
  3. C. 13
  4. D. 15

Correct answer: A. 1

Two l's and two o's are needed per copy, so the halving matters. The available counts are b 2, a 2, l 5, o 3 and n 1, and the minimum after halving is 1. Ignoring the halving on o gives 2, summing the counts gives 13, and the raw length gives 15.

More Pseudocode and Code Tracing questions

Exams that ask this topic