TopCoder problem "Reppity" used in SRM 198 (Division II Level One)



Problem Statement

    

Given a String, input, with up to 50 characters, find the length of the longest substring that appears at least twice (non-overlapping) in input. If no substring appears twice, non-overlapping, return 0.

Strings are case sensitive, and only upper case letters and lower case letters are allowed in input.

For example, in the string "ABCDEXXXYYYZZZABCDEZZZYYYXXX" the longest substring which appears at least twice is "ABCDE". These two substrings do not overlap so you would return 5.

 

Definition

    
Class:Reppity
Method:longestRep
Parameters:String
Returns:int
Method signature:int longestRep(String input)
(be sure your method is public)
    
 

Notes

-We are looking for subSTRINGS not subSEQUENCES. All of the elements of a substring appear consecutively in the original string. In other words, the substring can be formed from the original string by deleting zero or more characters from the begining and deleting zero or more characters from the end, but NO deletions from the middle are allowed.
 

Constraints

-input will contain between 1 and 50 characters inclusive.
-Each character in input will be between 'a' and 'z' inclusive or between 'A' and 'Z' inclusive.
 

Examples

0)
    
"ABCDEXXXYYYZZZABCDEZZZYYYXXX"
Returns: 5
The example from above.
1)
    
"abcdabcdabcdabCD"
Returns: 6
"abcdab"+"cd"+"abcdab"+"CD"
2)
    
"abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy"
Returns: 25
3)
    
"againANDagainANDagainANDagainANDagainANDagain"
Returns: 21
4)
    
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX"
Returns: 0

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=5073&pm=2314

Writer:

Rustyoldman

Testers:

brett1479 , schveiguy

Problem categories:

Brute Force