Group Service Log Lines by Correlation ID in Arrival Order

Last updated: November 29, 2026

Quick Overview

Given raw log lines in the form `timestamp|correlationId|message`, group the messages by correlation ID, keeping groups in first-seen order and messages in arrival order, and report how many lines were malformed.

EPAM Systems
Coding & Algorithms
Software Engineer
EPAM Systems
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given raw log lines in the form `timestamp|correlationId|message`, group the messages by correlation ID, keeping groups in first-seen order and messages in arrival order, and report how many lines were malformed.

A warm-up in the style of an EPAM live-coding screen for engineers who will support microservice estates on client accounts, where tracing one request across services from mixed logs is daily work. The interviewer checks clean parsing, a sensible data structure for ordered grouping, and whether you think about dirty input before being told to.

What the Interviewer Expects
  • Ask about the delimiter, whether messages may contain the delimiter, and what counts as malformed
  • Use an insertion-ordered map so group order is first-seen without an extra sort
  • Split with a max split count so pipes inside messages survive
  • Count and skip malformed lines instead of crashing
  • State O(n) time and space and test with an empty input
Key Topics to Cover
string parsing
ordered dictionaries
input validation
log correlation
streaming
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
  • How would you change this if the input were a 50 GB file that does not fit in memory?
  • How would you also return the time span (first to last timestamp) per correlation ID?
  • What if lines from the same request can arrive out of timestamp order?
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: an iterable of strings. Output: a list of (correlation_id, [messages]) in the order each ID first appeared, plus a malformed count. A line is malformed if it has fewer than three fields or an...

High-Level Design

One pass. For each line, split('|', 2) gives at most three parts, so the third part keeps any extra pipes. Python dicts (and OrderedDict) preserve insertion order, so setdefault(cid, []) both cr...


Submit Your Answer
Markdown supported

Related Questions