FastPrepEmail Log Processing, Grouping, and Sorting
Problems/Email Log Processing, Grouping, and Sorting

Email Log Processing, Grouping, and Sorting

Stripe logoStripe● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

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.

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

solveEmailLogGroupingAndSorting(input: String) → String[]

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.

Examples

Example 1

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

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

Constraints

  • Use the limits and requirements stated in the prompt.

More Stripe problems

  • Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
  • Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
  • Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String[] solveEmailLogGroupingAndSorting(String input) {
        // write your code here
    }

}
Checking account…