3436. Find Valid Emails LeetCode Solution

In this guide, you will get 3436. Find Valid Emails LeetCode Solution with the best time and space complexity. The solution to Find Valid Emails problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Find Valid Emails solution in C++
  4. Find Valid Emails solution in Java
  5. Find Valid Emails solution in Python
  6. Additional Resources
3436. Find Valid Emails LeetCode Solution image

Problem Statement of Find Valid Emails

Table: Users

+—————–+———+
| Column Name | Type |
+—————–+———+
| user_id | int |
| email | varchar |
+—————–+———+
(user_id) is the unique key for this table.
Each row contains a user’s unique ID and email address.

Write a solution to find all the valid email addresses. A valid email address meets the following criteria:

It contains exactly one @ symbol.
It ends with .com.
The part before the @ symbol contains only alphanumeric characters and underscores.
The part after the @ symbol and before .com contains a domain name that contains only letters.

Return the result table ordered by user_id in ascending order.

Example:

Input:
Users table:

+———+———————+
| user_id | email |
+———+———————+
| 1 | alice@example.com |
| 2 | bob_at_example.com |
| 3 | charlie@example.net |
| 4 | david@domain.com |
| 5 | eve@invalid |
+———+———————+

Output:

+———+——————-+
| user_id | email |
+———+——————-+
| 1 | alice@example.com |
| 4 | david@domain.com |
+———+——————-+

Explanation:

alice@example.com is valid because it contains one @, alice is alphanumeric, and example.com starts with a letter and ends with .com.
bob_at_example.com is invalid because it contains an underscore instead of an @.
charlie@example.net is invalid because the domain does not end with .com.
david@domain.com is valid because it meets all criteria.
eve@invalid is invalid because the domain does not end with .com.

See also  1217. Minimum Cost to Move Chips to The Same Position LeetCode Solution

Result table is ordered by user_id in ascending order.

Example not found

Constraints not found

Complexity Analysis

  • Time Complexity: Google AdSense
  • Space Complexity: Google Analytics

3436. Find Valid Emails LeetCode Solution in C++

SELECT user_id, email
FROM Users
WHERE email REGEXP '^[A-Za-z0-9_]+@[A-Za-z]+\.com$'
ORDER BY 1;
/* code provided by PROGIEZ */

3436. Find Valid Emails LeetCode Solution in Java

N/A
// code provided by PROGIEZ

3436. Find Valid Emails LeetCode Solution in Python

N/A
# code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.