TopcoderArchiveVisit Topcoder
SRM25 May 2011
SRM 518

TwiceString

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a String s. Return the shortest string which contains s as a contiguous substring twice.

Note that two occurrences of s may overlap. For example, "ababa" contains "aba" twice.

Definition

Class:
TwiceString
Method:
getShortest
Parameters:
String
Returns:
String
Method signature:
String getShortest(String s)
(be sure your method is public)

Notes

  • The shortest string which contains s as a contiguous substring twice is always unique.

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character in s will be a lowercase letter ('a'-'z').

Examples

  1. "aba"
    Returns: "ababa"
    This is the example shown in the problem statement.
  2. "xxxxx"
    Returns: "xxxxxx"
  3. "topcoder"
    Returns: "topcodertopcoder"
  4. "abracadabra"
    Returns: "abracadabracadabra"
Back to all problems