GATE IT 2005 · Arrays & Matrix Representation

MCQ · 1 mark · Problem PROG-DSTR-0219

A function \(f\) defined on stacks of integers satisfies the following properties. \(f(\emptyset) = 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

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionOfficial GATE Answer Key: Option C.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/3758/gate2005-it-13

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com