FastPrepMaximum Suffix–Prefix Overlap
Problems/Maximum Suffix–Prefix Overlap

Maximum Suffix–Prefix Overlap

Cresta logoCresta● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Cresta online assessment. The report asks directly for the maximum overlap between the end of one string and the start of another, checking from the longest length down. We chose the alphabet, the empty case, and the limits. Our version is about 95% the same as the reported question.

Given strings first and second, return the largest integer k such that the last k characters of first equal the first k characters of second.

The overlap may use an entire input string. Length 0 is always allowed. For this exercise, assume the inputs contain only lowercase English letters; an empty input therefore yields 0.

Function

maximumOverlap(first: String, second: String) → int

Examples

Example 1

first = "ababc"second = "bca"return = 2

The longest matching suffix and prefix are both bc, of length 2.

Example 2

first = "aaaa"second = "aa"return = 2

The full second string can overlap, so the answer is 2.

Example 3

first = "cat"second = "dog"return = 0

No nonempty suffix-prefix pair agrees.

Constraints

  • 0 <= first.length, second.length <= 2 × 10^4.
  • Both strings contain only lowercase English letters.

More Cresta interview questions

  • Decode Words with Anagram KeysOA · Seen Oct 2026
  • Find a File in a Directory SnapshotOA · Seen Oct 2026
  • Leaves Remaining After WindOA · Seen Oct 2026
  • Particle Moves to TargetOA · Seen Jul 2026
  • Rightward Bacteria ConsumptionOA · Seen Jul 2026
  • Top Three Companies by ProfitOA · Seen Jul 2026
  • Peak Chat Load Across AgentsPHONE SCREEN · Seen Nov 2026
  • File Storage ServicePHONE SCREEN · Seen Nov 2026
  • Dynamic Least-Loaded Job DispatcherPHONE SCREEN · Seen Oct 2026
  • Feature Flag Evaluation EngineONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Minimum Changes for Distinct Adjacent CharactersHeadlands Technologies · OAHeadlands Technologies interview questions
  • Theme Park Shuttle Wait TimeAirbnb · OAAirbnb interview questions
  • REST API: Country CodesHackerRank · OAHackerRank interview questions
  • Fill One Exact-Length Binary WindowAmazon · OA
  • Remove Vowels from a StringHSBC · OAHSBC interview questions
  • Branch with the Most FilesCapital One · OACapital One interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Robot Stops Left or Right (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions

Cresta interview experiences

  • Cresta Senior SWE Coding Round Interview Experience: 1 Experience
All Cresta interview questionsSee Cresta hiring insights
Saved
class Solution {
    public int maximumOverlap(String first, String second) {
        // write your code here
    }

}
Checking account…