Description
Solutions
Submission
Str with Longest Len 📐
🔥 FULLTIME

A prefix of a string S is any leading contiguous part of S. For example, the string "codility" has the following prefixes: "", "c", "co", "cod", "codi", "codil", "codili", "codilit", and "codility". A prefix of S is called proper if it is shorter 📏 than S.

A suffix of a string S is any trailing contiguous part of S. For example, the string "codibility" has the following sufixes: "", "y", "ty", "ity", "lity", "ility", "dility", "odility" and "codility". A suffix of S is called proper if it is shorter than S.

Let's now write a func called strWithLongestLen(String S) in the editor 👉

Task of your func:

  • Find the len of the longest string that is both a proper suffix of S and a proper prefix of S.
  • Example 1:

    Input:  S = "abbabba"
    Output: "abba"
    Explanation:
    Proper prefixes of S are: "", "a", "ab", "abb", "abba", "abbab", "abbabb" Proper suffixes of S are: "", "a", "ba", "bba", "abba", "babba", "bbabba" String "abba", with the longest len, is both a proper prefix and a proper sufix of S

    Example 2:

    Input:  S = "codility"
    Output: ""
    Explanation:
    string "", with the longest len, is both a proper prefix and suffix of S
    Constraints:
    • 1 <= S.length() <= 1,000,000
    • String S consists only lower case english letters (a - z)
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: