Longest Happy Prefix
Problem statement
A string is a happy prefix of s when it is a non-empty proper prefix of s and is also a suffix of s.
Return the longest happy prefix. If none exists, return the empty string.
Function
longestPrefix(s: String) → StringExamples
Example 1
s = "level"return = "l"The prefix l is also the suffix, and no longer proper prefix matches.
Example 2
s = "ababab"return = "abab"The first four characters equal the last four characters.
Example 3
s = "a"return = ""A one-character string has no non-empty proper prefix.
Constraints
1 <= s.length <= 100000.scontains only lowercase English letters.