ProgrammingVery hardTCS NQT · Accenture

The sentence "to be or not to be to" is split into words, and the procedure below prints the most frequent word (ties go to the first word that reaches the top count). What is printed?

The sentence "to be or not to be to" is split into words, and the procedure below prints the most frequent word (ties go to the first word that reaches the top count). What is printed?
count each word; choose the word with the highest count (first in the list on ties)
Print the word
  1. A. to
  2. B. be
  3. C. or
  4. D. not

Correct answer: A. to

The word to occurs three times and be twice, so the most frequent word is to. Taking the second word gives be, the least frequent word with the first-occurrence tie rule is or, and the fourth word is not.

More Pseudocode and Code Tracing questions

Exams that ask this topic