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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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...