Question DSA-GRDY-0063
HardWhat is the output of this code?
def candy(r):
n = len(r); c = [1] * n
for i in range(1, n):
if r[i] > r[i - 1]: c[i] = c[i - 1] + 1
for i in range(n - 2, -1, -1):
if r[i] > r[i + 1]: c[i] = max(c[i], c[i + 1] + 1)
return sum(c)
print(candy([1, 0, 2]), candy([1, 2, 87, 87, 87, 2, 1]))
- A.
4 13
- B.
5 11
- C.
Sign up free to see the answer and a step-by-step explanation.