Check Whether a Merged Event Log Interleaves Two Service Logs

Last updated: November 29, 2026

Quick Overview

Two services each write an ordered log, and a collector produces a merged log. Given the two logs and the merged log as strings, return whether the merged log is an interleaving that preserves each service's order.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Two services each write an ordered log, and a collector produces a merged log. Given the two logs and the merged log as strings, return whether the merged log is an interleaving that preserves each service's order.

Merged logs are everywhere in AWS (CloudWatch, distributed tracing), and verifying that a merge preserved per-source order is a natural 2D DP. The interviewer checks why greedy matching fails when both logs can supply the next character.

What the Interviewer Expects
  • Reject early if lengths do not add up
  • Define ok[i][j] for prefixes a[:i] and b[:j]
  • Transition from consuming the next char of a or of b
  • Roll to one row
  • O(n * m) time
Key Topics to Cover
2D dynamic programming
interleaving strings
space optimization
log merging
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
  • Give an input where greedy two-pointer matching fails.
  • How would you return the assignment of each merged entry to its source?
  • What if there are k logs instead of two?
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

Input: strings a, b, merged (each character is an event). Output: True if merged can be split into subsequences equal to a and b....

High-Level Design

Greedy fails when both logs can supply the next character: with a = aab, b = aac, merged = aacaab, greedily taking from a first consumes aa from a and then gets stuck on c unless it backtrac...


Submit Your Answer
Markdown supported