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
  1. A. 3
  2. B. 2
  3. C. 4
  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.

More Pseudocode and Code Tracing questions

Exams that ask this topic