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)
  1. A. 14
  2. B. 1
  3. C. 3
  4. 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.

More Pseudocode and Code Tracing questions

Exams that ask this topic