Skip to content

Practice Find Valid Emails

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3436
LeetCode Problem

Find Valid Emails

Problem Statement

Table Users has user_id INT and email VARCHAR. Keep addresses with one @, a nonempty local part containing only English letters, digits, or underscores, and a nonempty letter-only domain followed by the literal suffix .com. Return user_id and email ordered by user_id ascending. These are this exercise's rules, not a general-purpose email standard. Practice approach: Use a whole-string match for the local part, @, domain, and escaped dot before com. Do not allow punctuation in the local part, digits in the domain, extra @ characters, or trailing text. Test the actual case behavior of the database regex operator.

Source: Find Valid Emails on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
{
  "Users": [
    {
      "user_id": 1,
      "email": "a_2@Mail.com"
    },
    {
      "user_id": 2,
      "email": "a.b@mail.com"
    },
    {
      "user_id": 3,
      "email": "a@ma1l.com"
    },
    {
      "user_id": 4,
      "email": "a@@mail.com"
    },
    {
      "user_id": 5,
      "email": "b@mail.comx"
    },
    {
      "user_id": 6,
      "email": "b@mail.com"
    }
  ]
}
Output
[
  {
    "user_id": 1,
    "email": "a_2@Mail.com"
  },
  {
    "user_id": 6,
    "email": "b@mail.com"
  }
]
Explanation

An underscore and digit are allowed before @, but a dot there or a digit in the domain is not.

Constraints

user_id is unique.
The suffix is .com, and the domain before it contains only letters.

Related LeetCode Problems

Practice more problems similar to Find Valid Emails.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.