← Questions

Filter contacts by email domain

0
StripeCodingLast asked Jan 2026

A coding interview question asked in Stripe's onsite coding (debug, integrate, build) round, last asked Jan 2026. It tests strings, parsing and validation.

Contacts arrive as rows name,email,phone. Given a domain, return the original rows whose email address belongs to exactly that domain, in input order. Skip malformed rows and malformed email addresses.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • filter_by_domain(contacts: list[str], domain: str) -> list[str]
    • The requested domain may start with one optional @, which is ignored.
    • A well-formed row has exactly two commas.
    • A valid email has exactly one @ and a non-empty part before it.
    • The email's domain must equal the requested domain, compared without regard to letter case. A subdomain does not match.
    • Return the rows unchanged.

Example

filter_by_domain(["Alice,alice@example.com,111", "Bob,bob@other.com,222", "Cara,cara@EXAMPLE.COM,333"],
                 "example.com")
->  ["Alice,alice@example.com,111", "Cara,cara@EXAMPLE.COM,333"]

filter_by_domain(["A,a@shop.io,1", "B,b@sub.shop.io,2", "C,invalid,3"], "@shop.io")
->  ["A,a@shop.io,1"]                       # sub.shop.io is not shop.io; "invalid" has no @

filter_by_domain(["A,@example.com,1", "B,b@@example.com,2", "C,c@example.org,3"], "example.com")
->  []                                      # empty local part, two @, another domain

Constraints

  • Up to 100,000 rows, each at most 500 characters.
  • After removing the optional @, the domain is non-empty and has no whitespace, comma or @.
  • No trimming: only the domain's letter case is ignored.

Clarifying questions

  • Should subdomains match (sub.shop.io for shop.io)?
  • Is the comparison case-insensitive for the domain only, or for the whole address?
  • Should whitespace around fields be trimmed?
  • Is a quoted CSV field with a comma inside possible?

What a strong answer covers

  • Normalizing the requested domain once (strip one @, lower-case it).
  • Splitting each row into exactly three fields and rejecting any other count.
  • Checking the email with count("@") == 1 and a non-empty local part, then comparing the lower-cased domain.
  • O(total characters) time, one pass, input order kept.
  • Tests for each kind of malformed row and address, case differences and subdomains.

Follow-ups

  • Match subdomains too, as an option.
  • Group all contacts by domain and return the top domains by count.
  • Read the rows from a large CSV file with quoted fields.

Where it's asked

  • Stripe · Onsite coding: debug, integrate, build · Last asked Jan 202660 min · Project editor with starter code and tests: fix bugs in an unfamiliar codebase, wire an external API spec into a service, or complete a skeleton in parts · Varies by session: some onsites have one AI-assisted session and an integration session without AI

What it tests

strings · parsing · validation

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding