ProgrammingHardCapgemini · Infosys pattern
What will be the output of the following pseudocode (how many output rows a zigzag string conversion uses)?
What will be the output of the following pseudocode (how many output rows a zigzag string conversion uses)?
Function numRowsUsed(String s, Integer numRows)
return min(numRows, length(s))
End Function
Print numRowsUsed("PAYPALISHIRING", 3)- A. 14
- B. 1
- C. 3
- D. 4
Correct answer: C. 3
The string 'PAYPALISHIRING' has 14 characters, far more than numRows=3, so the number of rows actually used is capped at min(3, 14) = 3.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode (counting islands in a grid using flood-fill DFS)? (Grids are indexed from 0.) Integer…
- What will be the output of the following pseudocode (summing positive and negative matrix entries separately)? Integer mat[3][3] = {{1…
- What will be the output of the following pseudocode (counting distinct pairs whose difference is k)? (Arrays are indexed from 0.) Integer…
- What will be the output of the following pseudocode (2x2 matrix multiplication)? Integer A[2][2] = {{1, 2}, {3, 4}} Integer B[2][2] = {{5…
- What will be the output of the following pseudocode (binary string to decimal)? String bits = "110101" Integer val = 0 for (each b in…
- What will be the output of the following pseudocode (finding the 1-based position of the rightmost set bit)? (All variables are integers…