Sort AWS Service Log Lines With Text Entries First
Last updated: November 29, 2026
Quick Overview
Each log line starts with an identifier followed by space-separated words. Text logs have words made of letters; numeric logs have words made of digits. Return the logs with all text logs first, sorted by content then identifier, followed by numeric logs in their original order.
Amazon
November 29, 20260
0
0 solved
Each log line starts with an identifier followed by space-separated words. Text logs have words made of letters; numeric logs have words made of digits. Return the logs with all text logs first, sorted by content then identifier, followed by numeric logs in their original order.
A long-running Amazon assessment staple, here framed around AWS service logs. The grader looks for a clean custom sort key, correct tie-breaking by identifier, and preserving the relative order of numeric logs (stability).
What the Interviewer Expects
- Split each line once into identifier and content
- Classify by the first content word
- Build a tuple sort key that encodes all three rules
- Rely on stable sort for numeric logs
- Avoid writing a hand-rolled comparator unless needed
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
- How would you sort a 50 GB log file that does not fit in memory?
- What if identifiers must be compared numerically when they contain digits?
- How would you make text comparison case insensitive?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Each log has at least one word after the identifier. Content words are either all letters or all digits for a given line. Output is a new list; input order of numeric logs must be preserved....
High-Level Design
Define key(line): split into ident, rest with split(' ', 1). If rest[0] is a digit, return (1,) so all numeric logs tie and stable sort keeps them in input order. Otherwise return `(0, rest,...