A happy prefix is defined as a non-empty substring that appears both at the beginning and at the end of a string, but it cannot be the entire string itself.
Given a string s, your task is to return the longest such prefix that also occurs as a suffix.
If no prefix matches a suffix, return an empty string.
Input: s = "abcdabc"
Output: "abc"
Explanation:
The prefixes are "a", "ab", "abc", ..." and the suffixes include "abc". The longest prefix appearing as a suffix is "abc".
Input: s = "aaaaa"
Output: "aaaa"
Explanation:
Since all characters are the same, every smaller prefix is also a suffix. The longest valid one is "aaaa".
Accepted:
Submission: