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)
- A. 1
- B. 2
- C. 13
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Children have ratings r = [1, 0, 2, 2, 1]. Each child gets at least one candy, and a child with a higher rating than a neighbour gets more…
- Let x = 0. For i from 1 to 10: if i mod 3 == 0 then x = x + i, otherwise x = x - 1. What is printed? x = 0 for i = 1 to 10 if i mod 3 == 0…
- A rope of length L is cut into two parts of lengths floor(L/2) and L - floor(L/2) whenever its length is 2 or more; the cost of a cut is…
- Jobs each take one unit of time and carry a deadline: 1, 1, 2, 3, 4, 4 (the last slot the job may use; slots are 1, 2, 3, ...). The…
- Events (start, end) are attended one per day, and an event may be attended on any day from start to end inclusive. Events: (1,2), (1,2)…
- Seven tasks with durations 7, 5, 4, 3, 2, 2, 1 are assigned to two identical machines. Tasks are taken in decreasing duration order, and…