AO
Back

Best Substring by Prefix/Suffix Match Score

OAAsync OALast reported March 2025Low Frequency

Problem Overview

Given three strings, text, prefixString and suffixString, score the substrings of text:

  • prefixScore: the length of the longest substring of text matching the end of prefixString.
  • suffixScore: the length of the longest substring of text matching the start of suffixString.
  • totalScore = prefixScore + suffixScore.

Return the substring of text that begins with the matched prefix, ends with the matched suffix, and has the highest total score. If several substrings tie on the total score, return the alphabetically lowest one.

Example (as posted)

text         = "engine"
prefixString = "raven"
suffixString = "ginkgo"

"en" (from engine) matches the end of rav"en"     -> prefixScore = 2
"gin" (from engine) matches the start of "gin"kgo -> suffixScore = 3
totalScore = 5, and the answer to return is "engin"

Notes from the reports

  • This was the second of two coding problems in a Citadel online assessment, reported three times (February and March 2025).
  • The tie rule (alphabetically lowest) appears in one report's wording of the prompt; the other two do not mention ties.
  • No input sizes, character set or function signature were reported.
  • Not stated in any report, so confirm or state your assumption:
    • Can the prefix match and the suffix match overlap inside the substring? The example does not decide it ("en" and "gin" sit side by side in "engin").
    • What to return when only one side matches, or nothing matches at all.
  • On method, one report says the solution uses dynamic programming and another says it should be solved with KMP.

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Dynamic programmingOne report says the solution is dynamic programming (the report does not show it). Longest-common-substring style tables give each position's match lengths in O(n * (|P| + |S|)).
KMPAnother report says it should be solved with KMP. Linear-time matching (KMP's prefix function or the Z-function) gives the same per-position lengths in O(n + |P| + |S|).

What Reports Emphasize

Edge cases probed: Substrings tied on the total score: return the alphabetically lowest (stated in one report's prompt).

Practice

Write your own against 10 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Citadel with friends?

Send them this page. It is free to read, no account needed.

More Citadel Questions

Free preview

Every question in the Citadel catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 62 Citadel questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Citadel · OA · Reported 3× across candidate reports
Is this helpful?