cswork / OAOpen practice workspace

SnowflakeOA #2

Text Score — Prefix + Suffix Match

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)Strings

Given three strings text, prefixString, and suffixString, find:

  • prefixScore: the longest substring of text matching the end of prefixString.
  • suffixScore: the longest substring of text matching the beginning of suffixString.

Sum the lengths of the two strings to get the textScore. The substring of text that begins with the matching prefix and ends with matching suffix, and has the highest textScore, is the correct value to return. If there are other substrings with equal textScore, return the lexicographically lowest substring.

Note: if the prefix and suffix overlap, return only the substring of text, not prefix + suffix.

Editorial

Loading solution…