ProgrammingHardAmazon OA · Infosys SP
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer arr[6] = {900, 940, 950, 1100, 1500, 1800}
Integer dep[6] = {910, 1200, 1120, 1130, 1900, 2000}
sort arr; sort dep
Integer i = 0, j = 0, cur = 0, best = 0
while (i < 6)
if (arr[i] <= dep[j])
cur = cur + 1
best = max(best, cur)
i = i + 1
else
cur = cur - 1
j = j + 1
end if
end while
Print best- A. 3
- B. 2
- C. 4
- D. 6
Correct answer: A. 3
best is the most trains at the station at once (minimum platforms). Between 11:00 and 11:20 the trains arriving at 9:40, 9:50 and 11:00 are all present: 3 platforms.
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 right shift) Integer x = 40, pos = 1 while ((x & 1) == 0) x = x >> 1…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 10, steps = 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; and / are evaluated left to…
- What will be the output of the following pseudocode? Integer h[6] = {2, 1, 5, 6, 2, 3}, best = 0 for (each i from 0 to 5) Integer mn =…
- What will be the output of the following pseudocode? String stream = "aabcbc" Integer cnt[26] = all 0 Queue q = empty for (each ch in…
- What will be the output of the following pseudocode? Procedure f(Integer n) if (n == 0) return end if Print n f(n - 1) Print n End…