ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

The word "mississippi" is examined by the procedure below, which counts how many different letters it contains. What is printed?

The word "mississippi" is examined by the procedure below, which counts how many different letters it contains. What is printed?
seen = empty set
for each character ch of the word
    add ch to seen
Print size of seen
  1. A. 11
  2. B. 2
  3. C. 4
  4. D. 7

Correct answer: C. 4

The distinct letters are m, i, s and p, so the answer is 4. The word length is 11, the letter p occurs twice, and counting letter changes gives 7.

More Pseudocode and Code Tracing questions

Exams that ask this topic