TopcoderArchive
SRM12 Jun 2004
SRM 198

Reppity

Problem statement, definition, constraints, and public examples.

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

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