Email Log Processing, Grouping, and Sorting
Reported by candidates from Stripe's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Stripe asked you to build an email log processor in May 2026. You're parsing a stream of logs, grouping them by sender, then sorting within each group by a three-tier rule: timestamp first, then receiver email, then subject. Finally, output the grouped senders in alphabetical order. This is a parsing and multi-key sorting problem, not a heavy algorithm one. StealthCoder will catch parse errors and sort bugs when you're live.
The problem
Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem. Original prompt Problem: Email Log Processing (Grouping + Rule-based Sorting) You are given a list of email event logs logs. Each log is a single line string in the format: timestamp: a non-negative integer (seconds since epoch) sender_email, receiver_email: strings without spaces subject: the remainder of the line starting from the 4th token; it may contain spaces (and may be empty) Your task is to group logs by sender_email, sort each group by specific rules, and print the result. Rules Group by sender_email. Within the same sender_email, sort logs by: timestamp ascending if equal, receiver_email lexicographically ascending if still equal, subject lexicographically ascending Output sender groups in lexicographical order of sender_email. Input Line 1: integer n, number of logs. Next n lines: one log per line. Output For each sender, print: sender: Then print each sorted log line as: Note: sender_email is not printed on the log lines. Constraints 1 <= n <= 2 * 10^5 0 <= timestamp <= 10^9 Each line length <= 300 Example Input 5 100 alice@a.com bob@b.com hello 90 alice@a.com carl@c.com meeting notes 90 dan@d.com e@e.com hi 90 alice@a.com bob@b.com a-subject 100 dan@d.com a@a.com ping Output sender: alice@a.com 90 bob@b.com a-subject 90 carl@c.com meeting notes 100 bob@b.com hello sender: dan@d.com 90 e@e.com hi 100 a@a.com ping Function Description Complete solveEmailLogGroupingAndSorting. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters. The returned string must match the expected standard output for the sample input. Use the limits and requirements stated in the prompt.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is nailing the sort key order without mixing it up. Parse each log into timestamp, sender, receiver, and subject (remainder of line). Group by sender in a hash map. For each group, sort by (timestamp ascending, receiver ascending, subject ascending). Then output the senders themselves in alphabetical order, with each log printed as timestamp, receiver, subject. Common pitfall: forgetting the subject can be empty, or mis-parsing the subject as everything after the third space instead of the fourth token. Another trap: sorting senders lexicographically at the end, not in the order they appeared. If you blank on the multi-key comparator, StealthCoder will feed it to you live.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Email Log Processing, Grouping, and Sorting cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Stripe's OA.
Stripe reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Email Log Processing, Grouping, and Sorting FAQ
How do I handle the subject field if it's empty?+
The subject is the remainder of the line starting from the 4th token. If there are only 3 tokens, the subject is an empty string. When you split, count carefully: timestamp, sender, receiver, then everything else is subject. Empty subjects sort first lexicographically.
What's the three-tier sort order again?+
Within a sender group, sort by timestamp (ascending), then receiver email (ascending), then subject (ascending). All ascending. Don't flip any of them. It's a stable multi-key sort, so use a comparator that checks timestamp first, then receiver, then subject in that order.
Do I output senders in the order they appeared in the input?+
No. Output senders in lexicographical (alphabetical) order. Parse all logs, group them, sort each group, then iterate through sender names in alphabetical order and print each group. This is often a trap.
How do I parse the log line correctly?+
Split on whitespace, but the subject is special. Take tokens 0 (timestamp), 1 (sender), 2 (receiver), then join tokens 3 onwards with spaces to form the subject. Don't use a simple split and index; handle the remainder carefully.
Is the output format 'sender: email' or just 'email'?+
Print 'sender: ' followed by the sender email on its own line. Then for each log in that sender's group, print timestamp, receiver, and subject separated by spaces. Check the example output carefully. No sender email in the log lines themselves.