Problem Statement

Given a string s of length n, one can generate an infinite cyclical sequence a0, a1, ... as follows. For each non-negative integer i, compute a zero-based index j as j = i%n. ai is equal to the j-th character of s.

You are given a String s. Return the shortest string which generates the same sequence as s.

Definition

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

Constraints

-s will contain between 1 and 50 characters, inclusive.
-Each character in s will be a digit ('0'-'9').

Examples

0)

 `"11111"`
`Returns: "1"`
 The sequence generated by this string is ai=1, which can be generated by the string "1".
1)

 `"234234234"`
`Returns: "234"`
2)

 `"567890"`
`Returns: "567890"`
3)

 `"0"`
`Returns: "0"`
4)

 `"678967"`
`Returns: "678967"`

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=9926

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13729&pm=9926

Nickolas

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Brute Force, String Manipulation