ProgrammingHardAmazon OA · Goldman Sachs OA
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer P[4][4] = all 0
Integer A[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
for (each i from 1 to 3)
for (each j from 1 to 3)
P[i][j] = A[i - 1][j - 1] + P[i - 1][j] + P[i][j - 1] - P[i - 1][j - 1]
end for
end for
Print P[3][3] - P[1][3] - P[3][1] + P[1][1]- A. 45
- B. 33
- C. 28
- D. 12
Correct answer: C. 28
P is a 2-D prefix-sum table, and the printed expression is the sum of the block of rows 2–3 and columns 2–3 of A: 5 + 6 + 8 + 9 = 28.
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? // BST: smaller keys go to the left, larger to the right Insert into an empty BST, in…
- What will be the output of the following pseudocode? Function ways(Integer n) if (n < 0) return 0 end if if (n == 0) return 1 end if…
- What will be the output of the following pseudocode? (substring(s, i, k) is the k characters starting at index i; / is integer division; +…
- What will be the output of the following pseudocode? Function f(Integer n) if (n == 0) return 0 end if if (n == 1) return 1 end if return…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[8] = {2, 0, 1, 2, 1, 0, 2, 1} Integer lo = 0…