ProgrammingModerateCognizant GenC Next · Infosys
What will be the output of the following pseudocode? (Strings are indexed from 0; + joins strings)
What will be the output of the following pseudocode? (Strings are indexed from 0; + joins strings)
String s = "AAABCCDAA", r = ""
Integer i = 0, j
while (i < length(s))
j = i
while (j < length(s) AND s[j] == s[i])
j = j + 1
end while
r = r + s[i] + toString(j - i)
i = j
end while
Print r- A. A3B1C2D1A2
- B. A5B1C2D1
- C. A3BC2DA2
- D. A3B1C2D1A1
Correct answer: A. A3B1C2D1A2
This is run-length encoding of consecutive runs, not a count of letters: AAA, B, CC, D, AA give A3B1C2D1A2. Counting all A's together gives the trap A5….
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Function f(Integer n) if (n ==…
- What will be the output of the following pseudocode? (ref means the argument is passed by reference; other parameters are copies)…
- What will be the output of the following pseudocode? (/ is integer division) Stack st = empty for each token t in "6 2 3 + - 3 8 2 / + "…
- What will be the output of the following pseudocode? Integer a = 144, b = 89, t, steps = 0 while (b != 0) t = a mod b a = b b = t steps =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; , / and mod have equal…
- What will be the output of the following pseudocode? (& is bitwise AND, >> is right shift) Integer s = 0, x, t for (each i from 1 to 16) x…