ProgrammingHardAmazon OA · Infosys SP
What will be the output of the following pseudocode? (substring(t, i, k) is the k characters starting at index i; indices start at 0)
What will be the output of the following pseudocode? (substring(t, i, k) is the k characters starting at index i; indices start at 0)
String s1 = "ABCDE", s2 = "DEABC"
String t = s1 + s1
Integer pos = -1
for (each i from 0 to length(t) - length(s2))
if (substring(t, i, length(s2)) == s2)
pos = i
break
end if
end for
Print t, pos- A. ABCDEABCDE 2
- B. ABCDEABCDE -1
- C. ABCDEABCDE 3
- D. ABCDEDEABC 5
Correct answer: C. ABCDEABCDE 3
s2 is a rotation of s1 exactly when it appears inside s1 + s1 = ABCDEABCDE. DEABC starts at index 3: ABC|DEABC|DE. Output ABCDEABCDE 3.
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? (& is AND, ^ is XOR, << is left shift) Integer a = 13, b = 11, carry, rounds = 0…
- What will be the output of the following pseudocode? ((b & 1) is evaluated before == ; & is AND, << and >> are shifts) Integer a = 13, b =…
- What will be the output of the following pseudocode? (^ is XOR, >> is right shift) Integer s = 0, g for (each i from 0 to 7) g = i ^ (i >>…
- What will be the output of the following pseudocode? Function possible(Integer out[5]) Stack st = empty Integer next = 1 for (each i from…
- What will be the output of the following pseudocode? Integer coins[4] = {9, 6, 5, 1} // sorted largest first Integer amt = 11, used = 0…
- What will be the output of the following pseudocode? Integer a[8] = {10, 9, 2, 5, 3, 7, 101, 18} Integer L[8], best = 0 for (each i from 0…