Question PSC-ARR-0074
HardWhat will be printed by the following pseudocode?
Integer a[6] = {1, -2, 3, 10, -4, 7}
Integer i, cur = 0, best = a[0], start = 0, bs = 0, be = 0
for (each i from 0 to 5)
if (cur <= 0)
cur = a[i]
start = i
else
cur = cur + a[i]
end if
if (cur > best)
best = cur; bs = start; be = i
end if
end for
Print best, bs, be
- A.
13 2 3
- B.
16 2 5
- C.
Sign up free to see the answer and a step-by-step explanation.