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- A. 11
- B. 2
- C. 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- A palindrome check on "racecar" uses two pointers from both ends, comparing one pair per step and stopping early on a mismatch. The…
- The string "abcabcbb" is scanned with a sliding window that keeps the longest stretch without a repeated character. The procedure below…
- Scanning "abcab dab" as a string of letters, the procedure below counts the adjacent pairs that read "ab" (both letters next to each…
- Two words are checked as anagrams by comparing letter counts. The procedure below sums the absolute differences between the letter counts…
- The minimum number of insertions or deletions needed to make the string "abcca" a palindrome is len(s) - LPS(s), where LPS is the length…
- The edit distance (Levenshtein, insert/delete/replace each cost 1) between "kitten" and "sitting" is computed by the standard table. What…