FastPrepMerge Ordered Message Fragments
Problems/Merge Ordered Message Fragments

Merge Ordered Message Fragments

Veeam logoVeeam● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from a Veeam online assessment for a software engineer in test role, taken on 2026-11-25. The test had nine multiple-choice questions on shell scripting, containers and test design, and one coding task.

The report gives the merge rules and one example: join ordered fragments from left to right and write the longest overlap between the end of the text and the start of the next fragment only once; the message starts with 'A' and ends with 'Z'. It gives no limits.

The limits, the printable ASCII character set, the rule that an overlap may cover a whole fragment, the rule that a fragment found inside the text but not at its end is not merged, and Examples 2 and 3 are ours. Our version is about 90% the same as the reported question.

A message was split into fragments. You are given the fragments in their original order as a string array message. Rebuild the message by merging the fragments from left to right.

Start with message[0] as the text. Then, for each next fragment in order, find its overlap with the text: the largest integer k such that

  • 0 <= k <= min(text.length, fragment.length), and
  • the last k characters of the text equal the first k characters of the fragment.

Those k characters are written only once: append the fragment without its first k characters to the text.

  • Always use the longest overlap, not a shorter one.
  • The overlap is with the whole text built so far, not only with the previous fragment.
  • The overlap may be a whole fragment. If the text already ends with the fragment, nothing is added.
  • A fragment that appears inside the text but not at its end is not merged into it; only an overlap at the end of the text counts.

Return the rebuilt message. It starts with 'A' and ends with 'Z'.

Function

mergeFragments(message: String[]) → String

Examples

Example 1

message = ["Aghb","bfbcb","b===Z"]return = "Aghbfbcb===Z"

The text starts as "Aghb". It ends with "b" and "bfbcb" starts with "b"; the longer ends "hb", "ghb" and "Aghb" do not match its start, so the overlap is 1 and the text becomes "Aghbfbcb". That ends with "b" and "b===Z" starts with it, so the overlap is 1 again and the result is "Aghbfbcb===Z".

Example 2

message = ["Aabab","ababZ"]return = "AababZ"

Both "ab" (length 2) and "abab" (length 4) are at the end of "Aabab" and at the start of "ababZ". The longest one, length 4, is used, so only "Z" is added. Using the shorter overlap would give "AabababZ", which is wrong.

Example 3

message = ["Axyz","xy","y","Z"]return = "AxyzxyZ"

"xy" is inside "Axyz" but the text ends with "z", so the overlap is 0 and the text becomes "Axyzxy". That text already ends with "y", so the whole fragment "y" overlaps and nothing is added. "Z" has no overlap, so the result is "AxyzxyZ".

Constraints

  • 1 <= message.length <= 1000
  • 1 <= message[i].length <= 2000
  • The total length of all fragments is at most 3 * 10^4.
  • Every character is a printable ASCII character (codes 32 to 126, the space included).
  • message[0] starts with 'A', and the last fragment ends with 'Z'.

More Veeam interview questions

  • Integer to English Words in USD and INR StylesPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Longest Palindromic SubsequenceAXQ Capital · OA
  • Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Polynomial CoefficientsShopify · OAShopify interview questions
  • Basic Calculator IITypeSafe AI · OA
  • Count One-Swap Number PairsCapital One · OACapital One interview questions
  • Find a String Within One Mismatch of AllBarclays · OABarclays interview questions
  • Maximum String OperationsMicrosoft · OAMicrosoft interview questions
  • Reliable LLM Call with Independent Retry BudgetsStripe · OAStripe interview questions
  • Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
  • Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
See Veeam hiring insights
Saved
class Solution {
    public String mergeFragments(String[] message) {
        // Write your code here.
    }
}
Checking account…