ProgrammingHardAmazon OA · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
String s = "COMPUTER"
Integer i = 0, j = length(s) - 1
while (i < j)
while (i < j AND s[i] is not a vowel) i = i + 1
while (i < j AND s[j] is not a vowel) j = j - 1
swap(s[i], s[j])
i = i + 1
j = j - 1
end while
Print s- A. RETUPMOC
- B. CEMPUTOR
- C. COMPUTER
- D. CUMPOTER
Correct answer: B. CEMPUTOR
Two pointers swap the outermost vowels inward: O and E swap, then i and j meet at U, which stays. The vowels O, U, E become E, U, O: CEMPUTOR.
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? Function isSub(String a, String b) // is b a subsequence of a? Integer j = 0 for…
- What will be the output of the following pseudocode? String s = "ABBACA" Stack st = empty for (each ch in s) if (st not empty AND top(st)…
- What will be the output of the following pseudocode? Integer a[6] = {1, 2, 3, 4, 5, 6} Integer i = 0, j = 5 while (i < j) if (a[i] mod 2…
- What will be the output of the following pseudocode? Integer a[5] = {0, 1, 0, 3, 12}, k = 0 for (each i from 0 to 4) if (a[i] != 0)…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[6] = {-1, 0, 1, 2, -1, -4} sort a // {-4, -1…
- What will be the output of the following pseudocode? Integer a[3] = {5, -3, 5} Integer total = 0, curMax = 0, bestMax = a[0], curMin = 0…