FastPrepFastPrep
Problem Brief

Email Log Processing, Grouping, and Sorting

FULLTIMEOA
See Stripe online assessment and hiring insights

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> <sender_email> <receiver_email> <subject>

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: <sender_email>

Then print each sorted log line as:

<timestamp> <receiver_email> <subject>

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.

1Example 1

Input
input = "1\n0 a@a.com b@b.com hi"
Output
["sender: a@a.com", "0 b@b.com hi"]
Explanation

The returned string must match the expected standard output for the sample input.

Constraints

Limits and guarantees your solution can rely on.

Use the limits and requirements stated in the prompt.

public String[] solveEmailLogGroupingAndSorting(String input) {
    // write your code here
}
Input

input

"1\n0 a@a.com b@b.com hi"

Output

["sender: a@a.com", "0 b@b.com hi"]

Sign in to submit your solution.