Check Whether a Merged Chat Log Interleaves Two Message Threads

Last updated: November 29, 2026

Quick Overview

Given two thread transcripts a and b and a merged log c, decide whether c can be formed by interleaving the characters of a and b while keeping each thread's internal order.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given two thread transcripts a and b and a merged log c, decide whether c can be formed by interleaving the characters of a and b while keeping each thread's internal order.

A Messenger flavored 2D DP question from Meta onsites. Greedy matching fails when both threads offer the same next character, and the interviewer wants to see you notice that and set up a boolean table over prefixes.

What the Interviewer Expects
  • Reject immediately when lengths do not add up
  • Explain why greedy fails on ties
  • Define ok[i][j] for prefixes of a and b forming c[:i+j]
  • Compress to one row
  • Test empty strings on each side
Key Topics to Cover
2D dynamic programming
String interleaving
Boolean DP
Rolling array
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Can you return which thread each character of c came from?
  • What about three threads?
  • How would you solve it with BFS over (i, j) states?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs are strings a, b, c. Return True if c is an interleaving of a and b, meaning every character of c is taken in order from either a or b, and all of both are used. Lengths up to...

High-Level Design

If len(a) + len(b) != len(c) the answer is False. Otherwise let ok[i][j] be whether a[:i] and b[:j] interleave to form c[:i+j]. The last character c[i+j-1] came either from a[i-1] (needs...


Submit Your Answer
Markdown supported