Statistics

Problem Statement for "Reppity"

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. "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"

    Returns: 24

  6. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX"

    Returns: 0

  7. "x"

    Returns: 0

  8. "sdsdsdsdsdsdsdsdsdsdsdsdsd"

    Returns: 12

  9. "ohbabybabybabyboy"

    Returns: 5

  10. "thisexampleisbrokennoitisntohwait"

    Returns: 2

  11. "dobedobedobedobedobe"

    Returns: 8

  12. "tobeornottobeisnottobethequestion"

    Returns: 7

  13. "aa"

    Returns: 1

  14. "ab"

    Returns: 0

  15. "iiuiuioiiuiuuuiooopiooiuoiuoioiuiuiuo"

    Returns: 5

  16. "djkdkkfkfkdkskskkdkdfkkfkdkdkdjdkdkkkfjjkdfks"

    Returns: 5

  17. "kkdkkdkdkdkdkdkdkdkdkdkdkdkdkdkdkdkdkddkkd"

    Returns: 16

  18. "aaaaabbbbbaaaaabbbbbaaaaabbbbbaaaaabbbbbaaaaabbbbb"

    Returns: 20

  19. "aaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbbaaaaaaaaaa"

    Returns: 20

  20. "aabbaaabbbaaaabbbbaaaaabbbbbaaaaaabbbbbbaaaaabbbbb"

    Returns: 14

  21. "foglogfrogdoghogtogslogcogboggoggoogle"

    Returns: 3

  22. "catdogdogcatcatcatdogcatcatdog"

    Returns: 9

  23. "RustyoldmanrustyoldmanRustydustyoldman"

    Returns: 10

  24. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: 24

  25. "xxx"

    Returns: 1

  26. "zzzz"

    Returns: 2

  27. "cokedietcokedietcokedietcoke"

    Returns: 12

  28. "aaaboobaaoooboobaaeee"

    Returns: 6

  29. "abcdefghijklmnopqrstuvwxyza"

    Returns: 1

  30. "abcedefhijjklmnopqrstuvwxyz"

    Returns: 1

  31. "Rustyoldmanisthegreatestwriter"

    Returns: 2

  32. "ababdeaffdaaffd"

    Returns: 4

  33. "aa"

    Returns: 1

  34. "againANDagainANDagainANDagainANDagainANDagain"

    Returns: 21

  35. "abab"

    Returns: 2

  36. "ABCDEFGHIJKLMNOPabcdabcda"

    Returns: 4

  37. "abcAbc"

    Returns: 2

  38. "abcdefghzxbzx"

    Returns: 2

  39. "abcdefgxyzxyz"

    Returns: 3

  40. "abcdefghdkdk"

    Returns: 2

  41. "XYZYZX"

    Returns: 2

  42. "abcdabcdABCDEFGHI"

    Returns: 4

  43. "qwertyuiopaa"

    Returns: 1

  44. "ABCNBCN"

    Returns: 3

  45. "qwertyuzz"

    Returns: 1

  46. "AA"

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: