Connection Status:
Competition Arena > Reppity
SRM 198 · 2004-06-12 · by Rustyoldman · Brute Force
Class Name: Reppity
Return Type: int
Method Name: longestRep
Arg Types: (string)
Problem Statement

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.

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)
"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
Returns: 24

Submissions are judged against all 46 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Reppity with a public method int longestRep(string input) · 46 test cases · 2 s / 256 MB per case

Submitting as anonymous