StripeOA #13
Email Log Processing, Grouping, and Sorting
Estimated MediumJudge-ready
Topics (AI-labelled)HashingStringsIn-place Arrays
Given an email event log, group the events by sender. Sender groups are sorted lexicographically; within each group, events are sorted by timestamp in ascending order, then by recipient and subject in ascending lexicographic order. A subject may contain spaces and may also be empty.
Input
The first line contains n (1..200000), followed by n lines: a non-negative integer timestamp, sender, recipient, and subject. The sender and recipient contain no whitespace; the subject is the raw text from the 4th field of the line to the end of the line. Each line has at most 300 characters.
Output
First output the number of result lines; then, following the rules, output sender: <sender>, followed by that group's <timestamp> <recipient> [subject] lines. When the subject is empty, do not output an extra space.
Example 1
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:
7
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
Example 2
Input:
1
0 a@a.com b@b.com hi
Output:
2
sender: a@a.com
0 b@b.com hi
Example 3
Input:
3
7 z@e.com b@e.com same
7 z@e.com a@e.com same
7 a@e.com z@e.com
Output:
5
sender: a@e.com
7 z@e.com
sender: z@e.com
7 a@e.com same
7 b@e.com same
Editorial
Loading solution…