A function f defined on stacks of integers satisfies the following properties.…

PYQ GATE 2005

A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.

If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?

  1. A.

    6

  2. B.

    4

  3. C.

    3

  4. D.

    2

Attempted by 307 students.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…