cmi-entrance 2024 Q13

cmi-entrance · India · mscds Not Maths
13. In the following code, A is an array indexed from 0 whose elements are all positive integers, and n is the number of elements in A .
\begin{verbatim} function foo(A,n) { max = 0; curr = 0; for i from 1 to (n-1) { if A[i] > A[i-1] { curr = curr + 1; if curr > max { max = curr; } } else { curr = 0; } } return(max+1); } \end{verbatim}
If $A = [ 1,3,5,2,4,7,6,8 ]$, what will $f \circ \circ ( A , 8 )$ return?
(a) 2
(b) 3
(c) 4
(d) 5
13. In the following code, A is an array indexed from 0 whose elements are all positive integers, and n is the number of elements in A .

\begin{verbatim}
function foo(A,n) {
    max = 0;
    curr = 0;
    for i from 1 to (n-1) {
        if A[i] > A[i-1] {
            curr = curr + 1;
            if curr > max {
                max = curr;
            }
        } else {
            curr = 0;
        }
    }
    return(max+1);
}
\end{verbatim}

If $A = [ 1,3,5,2,4,7,6,8 ]$, what will $f \circ \circ ( A , 8 )$ return?\\
(a) 2\\
(b) 3\\
(c) 4\\
(d) 5\\