A function f defined on stacks of integers satisfies the following properties. f(ϕ)=0 and f (push(S)) = max (f(S), 0) + i for all stack S and integers. If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top. What is f(S)?
f(S) | max(f(S),0) | i |
Updated_f(S)=max(f(S),0)+i |
0 | 0 | 2 | 2 |
2 | 2 | -3 | -1 |
-1 | 0 | 2 | 2 |
2 | 2 | -1 | 1 |
1 | 1 | 2 | 3 |