Statistics

Problem Statement for "Serpentine"

Problem Statement

Printing a sequence of characters on a piece of paper could be faster if we were willing to write every other line from right to left. That way, we could avoid the "horizontal retrace" at the end of each line, simply moving down one spot and continuing to print horizontally in the opposite direction.

Create a class Serpentine that contains a method column that is given a String s and the width of the paper. It is also given the 0-based index of a column. It returns the contents of the indicated column that results from printing s using the above plan, printing the first row from left to right and alternating the direction of successive rows.

It should return the column as a String in top to bottom order.

Definition

Class:
Serpentine
Method:
column
Parameters:
String, int, int
Returns:
String
Method signature:
String column(String s, int width, int index)
(be sure your method is public)

Constraints

  • s has length between 1 and 50 inclusive
  • s contains only uppercase letters 'A'-'Z'
  • width is between 1 and 50 inclusive
  • index is between 0 and width-1 inclusive

Examples

  1. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    8

    0

    Returns: "APQ"

    ABCDEFGH PONMLKJI QRSTUVWX ZY index 0 refers to the first column. Note that the returned String must not contain a trailing space.

  2. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    8

    6

    Returns: "GJWZ"

  3. "ABCDEFG"

    10

    8

    Returns: ""

  4. "THISISATEST"

    4

    2

    Returns: "IST"

  5. "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"

    1

    0

    Returns: "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"

  6. "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"

    50

    49

    Returns: "X"

  7. "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"

    49

    48

    Returns: "WX"

  8. "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"

    2

    1

    Returns: "BCFGJKNORSVWZADEHILMPQTUX"

  9. "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"

    5

    4

    Returns: "EFOPYZIJST"

  10. "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"

    6

    4

    Returns: "EHQTCFOR"

  11. "Q"

    1

    0

    Returns: "Q"

  12. "Q"

    2

    0

    Returns: "Q"

  13. "Q"

    2

    1

    Returns: ""

  14. "Q"

    50

    0

    Returns: "Q"

  15. "ABCDEFGHIJKL"

    4

    0

    Returns: "AHI"

  16. "ABCDEFGHIJKL"

    4

    1

    Returns: "BGJ"

  17. "ABCDEFGHIJKL"

    4

    2

    Returns: "CFK"

  18. "ABCDEFGHIJKL"

    4

    3

    Returns: "DEL"

  19. "ABCDEFGHIJKL"

    5

    0

    Returns: "AJK"

  20. "ABCDEFGHIJKL"

    5

    3

    Returns: "DG"

  21. "ABCDEFGHIJKL"

    5

    4

    Returns: "EF"

  22. "QWERTYUIOPLKJHGFDSAZXCVBNMMNBVCXZASDFGHJKLPOIUYTRE"

    4

    3

    Returns: "RTKJZXNBDFOI"

  23. "ABCABCABCABC"

    3

    2

    Returns: "CACA"

  24. "ABCABCABC"

    3

    1

    Returns: "BBB"

  25. "ABCDFGTREUHJKILOPMNHYGC"

    4

    2

    Returns: "CGHING"

  26. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    8

    6

    Returns: "GJWZ"

  27. "ABCDEFGHIJKLMNOPQ"

    8

    1

    Returns: "BO"

  28. "ABCDEFGHIJKLMN"

    4

    3

    Returns: "DELM"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: