GATE DA 2024 — Question 39

Programming, Data Structures and AlgorithmsProgramming in PythonMCQ2 marks · −2/3 if wrongEasy

Consider the function computeS(\(X\)) whose pseudocode is given below:
code
1computeS(X)
2  S[1] ← 1
3  for i ← 2 to length(X)
4    S[i] ← 1
5    if X[i − 1] ≤ X[i]
6      S[i] ← S[i] + S[i − 1]
7    end if
8  end for
9  return S
10
Which 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]
Practise the full 2024 paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on Programming in PythonTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group