Statistics

Problem Statement for "StringMult"

Problem Statement

The definition of how to multiply a string by an integer follows:
  1. The empty string ("") multiplied by any integer is the empty string ("").
    For example: "" * 9 = ""
  2. Any string multiplied by 0 is the empty string ("").
    For example: "Terrific" * 0 = ""
  3. A non-empty string S multiplied by a positive integer k is the concatenation of k occurrences of S.
    For example: "Great" * 4 = "GreatGreatGreatGreat"
  4. A non-empty string S multiplied by a negative integer k is the concatenation of k occurrences of the reverse of S.
    For example: "Great" * -4 = "taerGtaerGtaerGtaerG"
Your method will take a String and an int and return their product.

Definition

Class:
StringMult
Method:
times
Parameters:
String, int
Returns:
String
Method signature:
String times(String sFactor, int iFactor)
(be sure your method is public)

Constraints

  • sFactor will have length between 0 and 50 inclusive.
  • iFactor will be between -50 and 50 inclusive.
  • sFactor will contain only letters ('A'-'Z' and 'a'-'z').
  • The length of the returned String (sFactor*iFactor) will be between 0 and 50, inclusive.

Examples

  1. "wOw"

    0

    Returns: ""

  2. "AbC"

    -3

    Returns: "CbACbACbA"

  3. "Boo"

    4

    Returns: "BooBooBooBoo"

  4. ""

    50

    Returns: ""

  5. "Racecar"

    -5

    Returns: "racecaRracecaRracecaRracecaRracecaR"

  6. "a"

    50

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  7. "a"

    -50

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  8. "abcdefgHIJKLMNOPqrstuvWXYZcdefgHIJKLMNOPqrstuvWXYZ"

    1

    Returns: "abcdefgHIJKLMNOPqrstuvWXYZcdefgHIJKLMNOPqrstuvWXYZ"

  9. "abcdefgHIJKLMNOPqrstuvWXYZcdefgHIJKLMNOPqrstuvWXYZ"

    -1

    Returns: "ZYXWvutsrqPONMLKJIHgfedcZYXWvutsrqPONMLKJIHgfedcba"

  10. "AbCdEfG"

    7

    Returns: "AbCdEfGAbCdEfGAbCdEfGAbCdEfGAbCdEfGAbCdEfGAbCdEfG"

  11. "AbCdEfG"

    -7

    Returns: "GfEdCbAGfEdCbAGfEdCbAGfEdCbAGfEdCbAGfEdCbAGfEdCbA"

  12. "uapoifusdapofuaspodu"

    0

    Returns: ""

  13. "oaiufpoiasudfpoiuasioasdu"

    2

    Returns: "oaiufpoiasudfpoiuasioasduoaiufpoiasudfpoiuasioasdu"

  14. "AAA"

    16

    Returns: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

  15. "AAA"

    -16

    Returns: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

  16. "GreatProblem"

    4

    Returns: "GreatProblemGreatProblemGreatProblemGreatProblem"

  17. "TerrificProblem"

    -3

    Returns: "melborPcifirreTmelborPcifirreTmelborPcifirreT"

  18. "Fubar"

    10

    Returns: "FubarFubarFubarFubarFubarFubarFubarFubarFubarFubar"

  19. "BlahBlah"

    4

    Returns: "BlahBlahBlahBlahBlahBlahBlahBlah"

  20. "test"

    5

    Returns: "testtesttesttesttest"

  21. "fubar"

    -10

    Returns: "rabufrabufrabufrabufrabufrabufrabufrabufrabufrabuf"

  22. "test"

    -5

    Returns: "tsettsettsettsettset"

  23. "Racejoemom"

    -5

    Returns: "momeojecaRmomeojecaRmomeojecaRmomeojecaRmomeojecaR"

  24. "googleplex"

    -5

    Returns: "xelpelgoogxelpelgoogxelpelgoogxelpelgoogxelpelgoog"

  25. "wOw"

    0

    Returns: ""

  26. "Suny"

    5

    Returns: "SunySunySunySunySuny"

  27. "nwfniwng"

    -3

    Returns: "gnwinfwngnwinfwngnwinfwn"

  28. "AbCdE"

    -9

    Returns: "EdCbAEdCbAEdCbAEdCbAEdCbAEdCbAEdCbAEdCbAEdCbA"

  29. "AbC"

    -3

    Returns: "CbACbACbA"


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: