CitadelOA #6
Calculate Score
Estimated MediumJudge-ready
Topics (AI-labelled)Strings
Choose a non-empty substring t of text. The prefix score is the longest length by which a prefix of t matches a suffix of prefixString; the suffix score is the longest length by which a suffix of t matches a prefix of suffixString. The total score is their sum, and the two matches may overlap; on a tie for the highest score, choose the lexicographically smallest t.
Input
Three lines: text, prefixString, and suffixString, in that order; each has length 1..50 and contains only lowercase letters; text is guaranteed to match at least one character on at least one side.
Output
Output the lexicographically smallest non-empty substring with the highest score.
Example 1
Input:
engine
raven
ginkgo
Output:
engin
Example 2
Input:
banana
bana
nana
Output:
banana
Example 3
Input:
ab
b
a
Output:
a
Example notes
The outputs of the three public examples are, in order: engin; banana; a. These answers were verified by independent enumeration or direct simulation.
Editorial
Loading solution…