GATE DA 2024 · Programming in Python

MCQ · 2 marks · Problem PROG-PYTH-0010

Consider the function \(computeS(X)\) whose pseudocode is given below: \(\underline{computeS(X)}\)
S[1] ← 1
for i ← 2 to length(X)
  S[i] ← 1
  if X[i-1] ≤ X[i]
      S[i] ← S[i]+S[i-1]
  end if
end for return SWhich ONE of the following values is returned by the function \(computeS(X)\) for \(X=[6,3,5,4,10]\) ?
  1. A
    [1, 1, 2, 3, 4]
  2. B
    [1, 1, 2, 3, 3]
  3. C
    [1, 1, 2, 1, 2]
  4. D
    [1, 1, 2, 1, 5]

Solve it on GATE DA practice →More Python Programming problems

Show the worked solutionOfficial GATE Answer Key: Option C.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/422933/gate-ds%26ai-2024-question-29

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