PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches

Quick Overview

This question evaluates the ability to implement date-based rule evaluation, efficient filtering and ordering over large account lists, and template rendering with attention to algorithmic efficiency and correctness.

  • medium
  • Stripe
  • Coding & Algorithms
  • Software Engineer

Generate Account Email Notifications

Company: Stripe

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are building an email notification scheduler for user accounts. You are given: 1. A list of user accounts. Each account has: - `account_id` - `created_day`: the day the account was created, represented as an integer - `expires_day`: the day the account expires, represented as an integer 2. A notification configuration describing which emails should be sent. Each rule has: - `name`: the email type, such as `welcome`, `expiration_reminder`, or `expired` - `trigger`: one of: - `on_create`: send when `created_day == current_day` - `days_before_expiration`: send when `expires_day - current_day == offset_days` - `after_expiration`: send when `current_day > expires_day` - `offset_days`: only used for `days_before_expiration` - `template`: the message to print Given `current_day`, the account list, and the notification configuration, print all emails that should be sent today. Each output line should include the `account_id`, the rule `name`, and the rendered message. If multiple rules apply to the same account, output all matching emails in the order the rules appear in the configuration. If no rules apply, output nothing for that account. Example: ```text current_day = 10 accounts = [ {account_id: "A1", created_day: 10, expires_day: 30}, {account_id: "A2", created_day: 2, expires_day: 13}, {account_id: "A3", created_day: 1, expires_day: 8} ] rules = [ {name: "welcome", trigger: "on_create", template: "Welcome!"}, {name: "three_day_reminder", trigger: "days_before_expiration", offset_days: 3, template: "Your account expires in 3 days."}, {name: "expired", trigger: "after_expiration", template: "Your account has expired."} ] ``` Expected output: ```text A1 welcome Welcome! A2 three_day_reminder Your account expires in 3 days. A3 expired Your account has expired. ``` Implement a function that generates the correct output efficiently for a large number of accounts and notification rules.

Quick Answer: This question evaluates the ability to implement date-based rule evaluation, efficient filtering and ordering over large account lists, and template rendering with attention to algorithmic efficiency and correctness.

You are building an email notification scheduler for user accounts. Given a `current_day`, a list of account records, and a list of notification rules, return all email notifications that should be sent on that day. Each account is a dictionary with: - `account_id`: string - `created_day`: integer - `expires_day`: integer Each rule is a dictionary with: - `name`: the email type - `trigger`: one of `on_create`, `days_before_expiration`, or `after_expiration` - `offset_days`: integer, only present when `trigger == "days_before_expiration"` - `template`: the message text to use verbatim A rule matches an account when: - `on_create`: `created_day == current_day` - `days_before_expiration`: `expires_day - current_day == offset_days` - `after_expiration`: `current_day > expires_day` Return the notifications in this order: 1. Accounts must be processed in the same order they appear in the input. 2. For a single account, if multiple rules match, their notifications must appear in the same order as the rules in the configuration. Each returned notification must be a string formatted as: `<account_id> <rule_name> <template>` If no rules match any account, return an empty list.

Constraints

  • 0 <= len(accounts) <= 200000
  • 0 <= len(rules) <= 200000
  • 0 <= current_day, created_day, expires_day, offset_days <= 10^9
  • For every account, created_day <= expires_day
  • Each rule trigger is one of: `on_create`, `days_before_expiration`, `after_expiration`
  • The total number of generated notifications will not exceed 200000

Examples

Input: (10, [{"account_id": "A1", "created_day": 10, "expires_day": 30}, {"account_id": "A2", "created_day": 2, "expires_day": 13}, {"account_id": "A3", "created_day": 1, "expires_day": 8}], [{"name": "welcome", "trigger": "on_create", "template": "Welcome!"}, {"name": "three_day_reminder", "trigger": "days_before_expiration", "offset_days": 3, "template": "Your account expires in 3 days."}, {"name": "expired", "trigger": "after_expiration", "template": "Your account has expired."}])

Expected Output: ["A1 welcome Welcome!", "A2 three_day_reminder Your account expires in 3 days.", "A3 expired Your account has expired."]

Explanation: A1 was created today, A2 expires in 3 days, and A3 is already expired.

Input: (5, [], [{"name": "welcome", "trigger": "on_create", "template": "Welcome!"}])

Expected Output: []

Explanation: There are no accounts, so no notifications are generated.

Input: (20, [{"account_id": "B1", "created_day": 20, "expires_day": 22}, {"account_id": "B2", "created_day": 10, "expires_day": 19}], [{"name": "two_day", "trigger": "days_before_expiration", "offset_days": 2, "template": "Account expires soon."}, {"name": "welcome", "trigger": "on_create", "template": "Welcome aboard."}, {"name": "expired", "trigger": "after_expiration", "template": "Account expired."}, {"name": "final_notice", "trigger": "days_before_expiration", "offset_days": 2, "template": "2 days left."}])

Expected Output: ["B1 two_day Account expires soon.", "B1 welcome Welcome aboard.", "B1 final_notice 2 days left.", "B2 expired Account expired."]

Explanation: B1 matches three rules. They must be emitted in the same order as the rule list: rule 0, then 1, then 3. B2 only matches the expired rule.

Input: (7, [{"account_id": "C1", "created_day": 1, "expires_day": 7}, {"account_id": "C2", "created_day": 7, "expires_day": 7}], [{"name": "expires_today", "trigger": "days_before_expiration", "offset_days": 0, "template": "Your account expires today."}, {"name": "welcome", "trigger": "on_create", "template": "Welcome!"}, {"name": "expired", "trigger": "after_expiration", "template": "Your account has expired."}])

Expected Output: ["C1 expires_today Your account expires today.", "C2 expires_today Your account expires today.", "C2 welcome Welcome!"]

Explanation: An offset of 0 means the reminder is sent on the expiration day. `after_expiration` does not trigger when `current_day == expires_day`.

Input: (12, [{"account_id": "D1", "created_day": 1, "expires_day": 20}], [{"name": "welcome", "trigger": "on_create", "template": "Welcome!"}, {"name": "two_day", "trigger": "days_before_expiration", "offset_days": 2, "template": "2 days left."}, {"name": "expired", "trigger": "after_expiration", "template": "Expired."}])

Expected Output: []

Explanation: D1 was not created today, does not expire in 2 days, and is not expired yet.

Hints

  1. Preprocess the rules by trigger type. For `days_before_expiration`, grouping by `offset_days` lets you find matching rules in O(1) for each account.
  2. You still need to preserve the original rule order. Store each rule's original index, then merge only the small set of matching rule groups for each account.
Last updated: May 23, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Assign Reviewers from Changed Files - Stripe (medium)
  • Calculate Transaction Fees - Stripe (medium)
  • Build an Account Transfer Ledger - Stripe (medium)
  • Implement Validation and String Compression - Stripe (hard)
  • Compute transaction fees from a CSV string - Stripe (hard)