← 返回 citadel 的题目列表Maximum Prefix and Suffix Score
类型:online_judge
Given three strings: text, prefixStr, and suffixStr. Define prefixScore as the maximal length of substring from text that can match prefixStr from the end. Define suffixScore as the maximal length of substring from text that can match suffixStr from the beginning. Return the substring of text corresponding to the maximum prefixScore + suffixScore. Use the KMP algorithm to solve this.
Input:
text: A string, length up to 10^5
prefixStr: A string, length up to 10^5
suffixStr: A string, length up to 10^5
Output:
The substring of text with maximum prefixScore + suffixScore.
Example:
Input:
text = "abcde"
prefixStr = "abc"
suffixStr = "de"
Output: abcde
Explanation: In this case, matching the entire text gives the maximum prefixScore and suffixScore with values 3 + 2 = 5.
Example
Input
text = "abcde"
prefixStr = "abc"
suffixStr = "de"