Question
Data Science and Artificial Intelligence Question on Programming in Python
Consider the function computes (X) whose pseudocode is given below :
S[1]←1computeS (X)
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 S
Which ONE of the following values is returned by the function computeS (X) for X= [6, 3, 5, 4, 10] ?
A
[1, 1, 2, 3, 4]
B
[1, 1, 2, 3, 3]
C
[1, 1, 2, 1, 2]
D
[1, 1, 2, 1, 5]
Answer
[1, 1, 2, 1, 2]
Explanation
Solution
The correct option is (C) : [1, 1, 2, 1, 2].