question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
minimum-element-after-replacement-with-digit-sum
Simple Swift Solution
simple-swift-solution-by-felisviridis-syet
Code
Felisviridis
NORMAL
2025-03-27T09:05:21.464077+00:00
2025-03-27T09:05:21.464077+00:00
2
false
![Screenshot 2025-03-27 at 12.04.15 PM.png](https://assets.leetcode.com/users/images/5466e5b0-d35d-4755-9a55-89f1497602bb_1743066274.7683833.png) # Code ```swift [] class Solution { func minElement(_ nums: [Int]) -> Int { var result = digitsSum(nums[0]) if nums.count == 1 { return result } for i in 1..<nums.count { result = min(result, digitsSum(nums[i])) } return result } private func digitsSum(_ num: Int) -> Int { var num = num, sum = 0 while num > 0 { sum += num % 10 num /= 10 } return sum } } ```
0
0
['Array', 'Swift']
0
minimum-element-after-replacement-with-digit-sum
🌟 Simple || Java || easy Approach || Beats 100%✅
simple-java-easy-approach-beats-100-by-s-bvg0
Proof👇🏻https://leetcode.com/problems/minimum-element-after-replacement-with-digit-sum/submissions/1587782467Complexity Time complexity:O(n) Space complexity:O(
SamirSyntax
NORMAL
2025-03-27T06:26:32.486452+00:00
2025-03-27T06:26:32.486452+00:00
2
false
# Proof👇🏻 https://leetcode.com/problems/minimum-element-after-replacement-with-digit-sum/submissions/1587782467 # Complexity - Time complexity:O(n) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity:O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int minElement(int[] nums) { for(int i=0; i<nums.length; i++){ nums[i] = digitSum(nums[i]); } int min = Integer.MAX_VALUE; for(int i=0; i<nums.length; i++){ min = (int)Math.min(min,nums[i]); } return min; } private int digitSum(int n){ int sum =0; while(n>0){ sum += n%10; n /= 10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
Brute-force solution with just easy :)
brute-force-solution-with-just-easy-by-b-x8yb
IntuitionTried to think about how get individual digit of the number and came up with "divide by 10" approachApproach Sum digits of each number after getting th
bek-shoyatbek
NORMAL
2025-03-26T23:32:41.185807+00:00
2025-03-26T23:32:41.185807+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Tried to think about how get individual digit of the number and came up with "divide by 10" approach # Approach <!-- Describe your approach to solving the problem. --> 1. Sum digits of each number after getting them by dividing by 10(it gives us last digit of the number) 2. Find min element with the help of Math.min and spead operator # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> Math.min is $$O(n)$$ + spead operator $$O(n)$$ + Array.map $$O(n)$$ + sumDigitsOfNum $$O(n)$$ = $$O(n)$$ - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> $$O(n)$$ # Code ```javascript [] /** * @param {number[]} nums * @return {number} */ var minElement = function(nums) { return Math.min(...nums.map(sumDigitsOfNum)) }; function sumDigitsOfNum(num){ let sum = 0; while(num>0){ sum+=num%10; num = parseInt(num/10); } return sum; } ```
0
0
['JavaScript']
0
minimum-element-after-replacement-with-digit-sum
Java&JS&TS Solution (JW)
javajsts-solution-jw-by-specter01wj-89fw
IntuitionApproachComplexity Time complexity: Space complexity: Code
specter01wj
NORMAL
2025-03-26T18:47:03.639118+00:00
2025-03-26T18:47:03.639118+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] public int minElement(int[] nums) { int min = Integer.MAX_VALUE; for (int num : nums) { int digitSum = getDigitSum(num); min = Math.min(min, digitSum); } return min; } private int getDigitSum(int num) { int sum = 0; while (num > 0) { sum += num % 10; num /= 10; } return sum; } ``` ```javascript [] var minElement = function(nums) { const digitSum = (num) => { let sum = 0; while (num > 0) { sum += num % 10; num = Math.floor(num / 10); } return sum; }; let min = Infinity; for (let num of nums) { min = Math.min(min, digitSum(num)); } return min; }; ``` ```typescript [] function minElement(nums: number[]): number { const digitSum = (num: number): number => { let sum = 0; while (num > 0) { sum += num % 10; num = Math.floor(num / 10); } return sum; }; let min = Infinity; for (const num of nums) { min = Math.min(min, digitSum(num)); } return min; }; ```
0
0
['Array', 'Math', 'Java', 'TypeScript', 'JavaScript']
0
minimum-element-after-replacement-with-digit-sum
my approach
my-approach-by-leman_cap13-w7q6
IntuitionApproachComplexity Time complexity: Space complexity: Code
leman_cap13
NORMAL
2025-03-24T15:45:12.897238+00:00
2025-03-24T15:45:12.897238+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```python3 [] class Solution: def minElement(self, nums: List[int]) -> int: result=[] for i in nums: a=sum(int(i) for i in str(i)) result.append(a) return min(result) ```
0
0
['Python3']
0
minimum-element-after-replacement-with-digit-sum
Easy java solution-
easy-java-solution-by-raj_sarkar-pv7i
IntuitionApproachComplexity Time complexity: Space complexity: Code
Raj_Sarkar
NORMAL
2025-03-19T20:35:00.779998+00:00
2025-03-19T20:35:00.779998+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int minElement(int[] nums) { int n=nums.length,min=Integer.MAX_VALUE; for(int i=0;i<n;i++){ nums[i]=sum(nums[i]); min=Math.min(min,nums[i]); } return min; } int sum(int n){ int sum=0; while(n!=0){ sum+=n%10; n/=10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
SIMPLE JAVA SOLUTION BEATS 100% OF JAVA SUBMISSION O(N) TIME COMPLEXITY👍👍👍❤
simple-java-solution-beats-100-of-java-s-ju0t
IntuitionTO FIND THE MINIMU SUM BEATS 100% OF JAVA SUBMISSION❤😍😍ApproachSIMPLE LINER SEARCHComplexity Time complexity: O(N) Space complexity: O(1)Code
Nadm781
NORMAL
2025-03-19T09:39:15.725210+00:00
2025-03-19T09:39:15.725210+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> TO FIND THE MINIMU SUM BEATS 100% OF JAVA SUBMISSION❤😍😍 # Approach <!-- Describe your approach to solving the problem. --> SIMPLE LINER SEARCH # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> O(N) - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> O(1) # Code ```java [] class Solution { public int minElement(int[] nums) { for(int i=0; i<nums.length;i++){ nums[i]=findSum(nums[i]); } return minimum(nums); } static int minimum(int[] arr){ int min=Integer.MAX_VALUE; for(int i=0;i<arr.length;i++){ if(arr[i]<min){ min=arr[i]; } } return min; } static int findSum(int num){ int sum=0; while(num>0){ int val=num%10; sum+=val; num=num/10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
0ms - beats 100% || efficient solution || complete solution
0ms-beats-100-efficient-solution-complet-r4zu
IntuitionWe need to compute the digit sum for each number in the array and then determine the smallest of these sums. The digit sum of a number is the sum of al
Mukund_TH04
NORMAL
2025-03-19T06:48:32.081979+00:00
2025-03-19T06:48:32.081979+00:00
2
false
# Intuition We need to compute the digit sum for each number in the array and then determine the smallest of these sums. The digit sum of a number is the sum of all its individual digits. --- # Approach 1. **Iterate through each number in the array:** For every number, calculate the sum of its digits by repeatedly extracting the last digit (using modulo 10) and then removing that digit (using division by 10). 2. **Update the minimum digit sum:** Use a variable to keep track of the minimum digit sum seen so far. 3. **Return the result:** After processing all numbers, return the minimum digit sum. --- # Complexity - **Time Complexity:** \( O(n \times d) \) Here, \( n \) is the number of elements in the array, and \( d \) is the number of digits in each number (which is constant with the given constraints). - **Space Complexity:** \( O(1) \) Only a few extra variables are used, so the space usage is constant. --- # Code ```cpp class Solution { public: int minElement(vector<int>& nums) { int res = INT_MAX; for (auto num : nums){ int sum = 0; int n = num; while(n > 0){ sum += n % 10; n /= 10; } res = min(res, sum); } return res; } }; ```
0
0
['C++']
0
minimum-element-after-replacement-with-digit-sum
Java solution beats 100%
java-solution-beats-100-by-moreshivam20-xdyu
ApproachSimple and easy approach first iterate through all numbers and then check digitSum of each number using modulo operator and compare using Math.min funct
moreshivam20
NORMAL
2025-03-17T05:11:56.753615+00:00
2025-03-17T05:11:56.753615+00:00
1
false
# Approach Simple and easy approach first iterate through all numbers and then check digitSum of each number using modulo operator and compare using Math.min function return min value # Code ```java [] class Solution { public int minElement(int[] nums) { int min = Integer.MAX_VALUE; for(int num : nums){ int digitSum = 0; // reset digitSum for each no. while(num>0){ digitSum = digitSum + num%10; num = num/10; } min = Math.min(min, digitSum); } return min ; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
2ms solution
2ms-solution-by-user4992xm-sd5t
IntuitionApproachComplexity Time complexity: Space complexity: Code
user4992Xm
NORMAL
2025-03-16T17:34:30.989829+00:00
2025-03-16T17:34:30.989829+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int minElement(int[] nums) { int min = nums[0]; for(int i=0; i<nums.length; i++){ int temp = nums[i]; char[] ch = String.valueOf(temp).toCharArray(); int sum = 0; for(int j=0; j<ch.length; j++){ sum += Character.getNumericValue(ch[j]); } min = Math.min(min, sum); } return min; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
Simple solution - beats 100% 🔥
simple-solution-beats-100-by-joshuaimman-059w
Complexity Time complexity: O(M * log N) Space complexity: O(1) Code
joshuaimmanuelin
NORMAL
2025-03-15T18:24:48.350876+00:00
2025-03-15T18:24:48.350876+00:00
3
false
# Complexity - Time complexity: O(M * log N) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int minElement(int[] nums) { int min = Integer.MAX_VALUE; for (int i = 0; i < nums.length; i++) { min = Math.min(min, nums[i] = sumOfDigit(nums[i])); } return min; } public int sumOfDigit(int n) { int sum = 0; while (n > 0){ sum += n % 10; n /= 10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
JAVA | | SimpleOne--;
java-simpleone-by-vasanth_kumar_29_19-8imc
IntuitionApproachComplexity Time complexity: Space complexity: Code
Vasanth_Kumar_29_19
NORMAL
2025-03-15T15:42:21.944903+00:00
2025-03-15T15:42:21.944903+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int minElement(int[] nums) { int min = Integer.MAX_VALUE; for(int i=0;i<nums.length;i++){ min = Math.min(min,nums[i]=sumOfDigit(nums[i])); } return min; } public int sumOfDigit(int num){ int sum = 0; while(num>0){ sum += num%10; num/=10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
SIMPLE C PROGRAM
simple-c-program-by-mr_jaikumar-ya97
IntuitionApproachComplexity Time complexity:0 MS Space complexity: Code
Mr_JAIKUMAR
NORMAL
2025-03-14T05:41:43.600924+00:00
2025-03-14T05:41:43.600924+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity:0 MS <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```c [] int sumdig(int n) { int sum=0; while(n!=0) { sum=sum+(n%10); n=n/10; } return sum; } int minElement(int* nums, int numsSize) { int temp; for(int i=0;i<numsSize;i++) { temp=sumdig(nums[i]); nums[i]=temp; } int min=nums[0]; for(int j=0;j<numsSize;j++) { if(nums[j]<min) { min=nums[j]; } } return min; } ```
0
0
['C']
0
minimum-element-after-replacement-with-digit-sum
Easiest solution
easiest-solution-by-aniketkumarsingh99-p4ss
IntuitionSum of digits on every element.ApproachEdit array elements with their sum then sort it and return the smallest element.Complexity Time complexity: O(n
AniketKumarSingh99
NORMAL
2025-03-13T18:05:41.961435+00:00
2025-03-13T18:05:41.961435+00:00
2
false
# Intuition Sum of digits on every element. # Approach Edit array elements with their sum then sort it and return the smallest element. # Complexity - Time complexity: O(n logn). - Space complexity: O(1). # Code ```cpp [] class Solution { public: int minElement(vector<int>& nums) { for(int i=0;i<nums.size();i++){ int sum=0; while(nums[i]>0){ sum+=nums[i]%10; nums[i]/=10; } nums[i]=sum; } sort(nums.begin(),nums.end()); return nums[0]; } }; ```
0
0
['C++']
0
minimum-element-after-replacement-with-digit-sum
Easy Java Solution || 1ms
easy-java-solution-1ms-by-prachijain-p38c
IntuitionApproachComplexity Time complexity: O(n) Space complexity: O(1) Code
prachijain
NORMAL
2025-03-13T16:29:29.555286+00:00
2025-03-13T16:29:29.555286+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(n) - Space complexity: O(1) # Code ```java [] class Solution { public int minElement(int[] nums) { int minVal=Integer.MAX_VALUE; for(int i=0;i<nums.length;i++){ nums[i]=digitSum(nums[i]); minVal=Math.min(minVal,nums[i]); } return minVal; } public static int digitSum(int num){ int sum=0; while(num>0){ sum+=num%10; num/=10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
Python
python-by-velanr-dy7g
IntuitionApproachComplexity Time complexity: Space complexity: Code
Velanr
NORMAL
2025-03-13T05:32:03.042487+00:00
2025-03-13T05:32:03.042487+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```python [] class Solution(object): def minElement(self, nums): """ :type nums: List[int] :rtype: int """ a=[] for i in nums: s=0 while i>0: n=i%10 s+=n i//=10 a.append(s) return min(a) ```
0
0
['Python']
0
minimum-element-after-replacement-with-digit-sum
Simple Solution by Baby Beginner
simple-solution-by-baby-beginner-by-chan-3h1k
IntuitionApproachComplexity Time complexity: Space complexity: Code
chandueddalausa
NORMAL
2025-03-12T18:55:13.349539+00:00
2025-03-12T18:55:13.349539+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```python3 [] class Solution: def minElement(self, nums: List[int]) -> int: li=[] for x in nums: tem=0 st=str(x) for y in range(len(st)): tem+=int(st[y]) li.append(tem) print(li) return min(li) ```
0
0
['Python3']
0
minimum-element-after-replacement-with-digit-sum
Beats 100%
beats-100-by-shohruh11-0j5f
Code
Shohruh11
NORMAL
2025-03-12T17:28:02.334018+00:00
2025-03-12T17:28:02.334018+00:00
2
false
# Code ```java [] class Solution { public int minElement(int[] nums) { int min = digSum(nums[0]); for(int i=1; i<nums.length; i++){ min = Math.min(min,digSum(nums[i])); } return min; } public int digSum(int a){ int sum = 0; while (a > 0){ sum += a % 10; a /= 10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
Minimum element after replacement with digit sum
minimum-element-after-replacement-with-d-f5u8
Code
AnushaYelleti
NORMAL
2025-03-12T13:34:23.739132+00:00
2025-03-12T13:34:23.739132+00:00
1
false
# Code ```python3 [] class Solution: def minElement(self, nums: List[int]) -> int: ans=[] for i in nums: c=0 for j in str(i): c+=int(j) ans.append(c) return min(ans) ```
0
0
['Python3']
0
minimum-element-after-replacement-with-digit-sum
The Maximum Returned Value has to be 36
the-maximum-returned-value-has-to-be-36-jan1j
This is pretty much just a standard solution for this problem.One thing to note is that the maximum returned value can only be 36. This is because the maximum v
nathannaveen
NORMAL
2025-03-11T13:45:58.888021+00:00
2025-03-11T13:45:58.888021+00:00
1
false
This is pretty much just a standard solution for this problem. One thing to note is that the maximum returned value can only be $$36$$. This is because the maximum value for `nums[i]` is $$10^4$$. So, the number with the greatest digit sum would be $$9999$$, getting a sum of $$9+9+9+9=36$$. So, we don't need to set the minimum value to a very large number or the maximum integer value, we can just set it to $$36$$. # Code ```golang [] func minElement(nums []int) int { min := 36 for _, n := range nums { x := 0 for n > 0 { x += n % 10 n /= 10 } if x < min { min = x } } return min } ```
0
0
['Go']
0
minimum-element-after-replacement-with-digit-sum
MinElement easy and simple solution in C || 100% Beat
minelement-easy-and-simple-solution-in-c-d823
Solution in CCode
jigarrathod
NORMAL
2025-03-10T18:28:21.409549+00:00
2025-03-10T18:28:21.409549+00:00
1
false
# Solution in C # Code ```c [] int minElement(int* nums, int numsSize) { int* arr = (int*)malloc(numsSize * sizeof(int)); int rem = 0; int value = 0; for (int i = 0; i < numsSize; i++) { int sum = 0; int num = nums[i]; while (num) { rem = num % 10; sum += rem; num /= 10; } arr[i] = sum; } value = arr[0]; for (int i = 1; i < numsSize; i++) { if (arr[i] < value) { value = arr[i]; } } free(arr); return value; } ```
0
0
['Array', 'Math', 'C']
0
minimum-element-after-replacement-with-digit-sum
PHP WARLORD
php-warlord-by-gilguff-b0a2
IntuitionApproachComplexity Time complexity: Space complexity: Code
Gilguff
NORMAL
2025-03-08T23:56:26.247655+00:00
2025-03-08T23:56:26.247655+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```php [] class Solution { /** * @param Integer[] $nums * @return Integer */ function minElement($nums) { $res = 1000000000; foreach ($nums as $num) { $count = 0; foreach (str_split($num) as $digit) { $count += $digit; } if ($count < $res) { $res = $count; } } return $res; } } ```
0
0
['PHP']
0
minimum-element-after-replacement-with-digit-sum
Simple solution in Java. Beats 100 %
simple-solution-in-java-beats-100-by-kha-61oi
Complexity Time complexity: O(n * log m) (where n is the number of elements in the nums array and m is the maximum value in the array) Space complexity: O(1)
Khamdam
NORMAL
2025-03-07T04:48:43.346195+00:00
2025-03-07T04:48:43.346195+00:00
4
false
# Complexity - Time complexity: O(n * log m) *(where n is the number of elements in the nums array and m is the maximum value in the array)* - Space complexity: O(1) # Code ```java [] class Solution { public int minElement(int[] nums) { for (int i = 0; i < nums.length; i++) { nums[i] = sumOfDigits(nums[i]); } int min = Integer.MAX_VALUE; for (int num : nums) { if (num < min) { min = num; } } return min; } private int sumOfDigits(int n) { int sum = 0; while (n > 0) { int lastDigit = n % 10; sum += lastDigit; n /= 10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
Easy Typescript Solution with Full Explanation
easy-typescript-solution-with-full-expla-lpyr
IntuitionApproachComplexity Time complexity: O(n∗log(max)) The function iterates through the nums array, which has a length of n. This gives us an O(n) factor
chetannada
NORMAL
2025-03-06T11:50:31.660694+00:00
2025-03-06T11:53:04.945815+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: $$O(n * log(max))$$ 1. The function iterates through the `nums` array, which has a length of `n`. This gives us an O(n) factor for the loop. 2. Inside the loop, the `sumOfDigits` function is called for each element. The `sumOfDigits` function converts the number to a string, splits it into an array of characters, and then uses the `reduce` method to calculate the sum of its digits. The time complexity of converting a number to a string and splitting it into an array is O(d), where `d` is the number of digits in the number. In the worst case, if the numbers are large, `d` can be proportional to log10(num), which is O(log(num)). 3. Therefore, the overall time complexity of the function is O(n * log(max)), where `max` is the largest number in the `nums` array. <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: $$O(log(max))$$ 1. The space used by the `min` variable is O(1) since it only stores a single number. 2. The `sumOfDigits` function creates an array of characters from the string representation of the number, which takes O(d) space, where `d` is the number of digits in the number. 3. However, since this space is used temporarily for each call to `sumOfDigits`, it does not accumulate across calls. Thus, the overall space complexity is O(d) for the largest number processed, which can be considered O(log(max)) in terms of the largest number in the `nums` array. <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```typescript [] function minElement(nums: number[]): number { let min: number = Infinity; function sumOfDigits(num) { // find sum of digits of num by coverting num to string and then array and use reduce method let digitSum: number = num.toString().split("").reduce((a, b) => +a + +b, 0); return digitSum; } for (let i = 0; i < nums.length; i++) { // invoke sumOfDigits() function to get sum let sum: number = sumOfDigits(nums[i]); // find minimum value between min and sum min = Math.min(min, sum); } return min; }; ```
0
0
['Array', 'Math', 'TypeScript']
0
minimum-element-after-replacement-with-digit-sum
Easy Javascript Solution with Full Explanation
easy-javascript-solution-with-full-expla-pod2
IntuitionApproachComplexity Time complexity: O(n∗log(max)) The function iterates through the nums array, which has a length of n. This gives us an O(n) factor
chetannada
NORMAL
2025-03-06T11:46:59.671514+00:00
2025-03-06T11:47:21.699028+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: $$O(n * log(max))$$ 1. The function iterates through the `nums` array, which has a length of `n`. This gives us an O(n) factor for the loop. 2. Inside the loop, the `sumOfDigits` function is called for each element. The `sumOfDigits` function converts the number to a string, splits it into an array of characters, and then uses the `reduce` method to calculate the sum of its digits. The time complexity of converting a number to a string and splitting it into an array is O(d), where `d` is the number of digits in the number. In the worst case, if the numbers are large, `d` can be proportional to log10(num), which is O(log(num)). 3. Therefore, the overall time complexity of the function is O(n * log(max)), where `max` is the largest number in the `nums` array. <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: $$O(log(max))$$ 1. The space used by the `min` variable is O(1) since it only stores a single number. 2. The `sumOfDigits` function creates an array of characters from the string representation of the number, which takes O(d) space, where `d` is the number of digits in the number. 3. However, since this space is used temporarily for each call to `sumOfDigits`, it does not accumulate across calls. Thus, the overall space complexity is O(d) for the largest number processed, which can be considered O(log(max)) in terms of the largest number in the `nums` array. <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```javascript [] /** * @param {number[]} nums * @return {number} */ var minElement = function (nums) { let min = Infinity; function sumOfDigits(num) { // find sum of digits of num by coverting num to string and then array and use reduce method let digitSum = num.toString().split("").reduce((a, b) => +a + +b, 0); return digitSum; } for (let i = 0; i < nums.length; i++) { // invoke sumOfDigits() function to get sum let sum = sumOfDigits(nums[i]); // find minimum value between min and sum min = Math.min(min, sum); } return min; }; ```
0
0
['Array', 'Math', 'JavaScript']
0
minimum-element-after-replacement-with-digit-sum
Super easy Python solution using simple logic | Beginner friendly
super-easy-python-solution-using-simple-dtwzk
Code
rajsekhar5161
NORMAL
2025-03-04T13:58:36.760829+00:00
2025-03-04T13:58:36.760829+00:00
3
false
# Code ```python [] class Solution(object): def minElement(self, nums): minimum=nums[0] for i in nums: sums=0 for num in str(i): sums+=int(num) minimum=min(minimum,sums) return minimum ```
0
0
['Array', 'Math', 'Python']
0
minimum-element-after-replacement-with-digit-sum
Simple Java Solution || Beats 100% || Beginner friendly
simple-java-solution-beats-100-beginner-xdyed
IntutionApproachComplexity Time complexity: O(n) Space complexity: O(1) Code
Aravind_3353
NORMAL
2025-03-03T17:31:43.599661+00:00
2025-03-03T17:31:43.599661+00:00
3
false
# Intution <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(n) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int minElement(int[] nums) { int res=Integer.MAX_VALUE; for(int i=0;i<nums.length;i++){ int sum=0; while(nums[i]>0){ int rem=nums[i]%10; sum+=rem; nums[i]/=10; } res=(sum<res)?sum:res; } return res; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
easy solution for beginers in java!!!!!!!!!!!
easy-solution-for-beginers-in-java-by-ch-5zbp
IntuitionApproachComplexity Time complexity: Space complexity: Code
CHURCHILL04
NORMAL
2025-03-01T03:44:08.428880+00:00
2025-03-01T03:44:08.428880+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { private int sumOfDigits(int num) { int sum = 0; while (num > 0) { sum += num % 10; num /= 10; } return sum; } public int minElement(int[] nums) { int min = Integer.MAX_VALUE; for (int num : nums) { min = Math.min(min, sumOfDigits(num)); } return min; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
Using Map and List Comprehension
using-map-and-list-comprehension-by-ruic-hrr2
IntuitionApproachUse map(int, str(num)) to convert each character (digit) back into an integer. Apply sum() for each "mapped object", which in this case is a li
Ruicookee
NORMAL
2025-02-27T03:22:48.085709+00:00
2025-02-27T03:22:48.085709+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. -->breaking each number down into their individual digits, sum them, and then determine the smallest sum # Approach <!-- Describe your approach to solving the problem. -->Convert each number into a string. Use map(int, str(num)) to convert each character (digit) back into an integer. Apply sum() for each "mapped object", which in this case is a list of digits Use min() # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ -->O(n*d), d being the avg number of digits per number - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ -->O(n) # Code ```python3 [] class Solution: def minElement(self, nums: List[int]) -> int: return min([sum(map(int,str(num))) for num in nums]) ```
0
0
['Python3']
0
minimum-element-after-replacement-with-digit-sum
Easy code IN JAVA
easy-code-in-java-by-abhisheksoni122004-l5fi
IntuitionApproachComplexity Time complexity: Space complexity: Code
abhisheksoni122004
NORMAL
2025-02-26T18:31:16.965686+00:00
2025-02-26T18:31:16.965686+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int minElement(int[] nums) { int min = Integer.MAX_VALUE; for(int num : nums){ min = Math.min(min , digitSum(num)); } return min; } private int digitSum(int n){ int sum = 0; while(n > 0){ sum += n % 10; n /= 10; } return sum; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
TRY DO YOUR OWN ALL THE BEST:)
try-do-your-own-all-the-best-by-srinath_-aui9
Code
Srinath_Y
NORMAL
2025-02-25T08:38:50.205930+00:00
2025-02-25T08:38:50.205930+00:00
0
false
# Code ```python [] class Solution(object): def minElement(self, nums): for i in nums: ans=0 a=nums.index(i) for j in str(i): ans+=int(j) nums[a]=ans ans=0 return min(nums) ```
0
0
['Python']
0
minimum-element-after-replacement-with-digit-sum
TRY DO YOUR OWN ALL THE BEST:)
try-do-your-own-all-the-best-by-srinath_-wboy
Code
Srinath_Y
NORMAL
2025-02-25T08:38:47.749345+00:00
2025-02-25T08:38:47.749345+00:00
0
false
# Code ```python [] class Solution(object): def minElement(self, nums): for i in nums: ans=0 a=nums.index(i) for j in str(i): ans+=int(j) nums[a]=ans ans=0 return min(nums) ```
0
0
['Python']
0
minimum-element-after-replacement-with-digit-sum
beats 90%
beats-90-by-iraklis_ch-cjhp
IntuitionApproachComplexity Time complexity: Space complexity: Code
Iraklis_Ch
NORMAL
2025-02-24T06:57:06.396832+00:00
2025-02-24T06:57:06.396832+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```python3 [] class Solution: def minElement(self, nums: List[int]) -> int: def sum_digits(n): count = 0 for digit in str(n): count += int(digit) return count min_val = float("inf") for x in nums: if sum_digits(x) < min_val: min_val = sum_digits(x) return min_val ```
0
0
['Python3']
0
minimum-element-after-replacement-with-digit-sum
Easy to understand Java Solution
easy-to-understand-java-solution-by-inee-b64h
ApproachActually we do not need to convert each number in the arrayinto a string and then iterate through the string to get the sum of the digits as Hint 1 impl
Ineedchezzborger
NORMAL
2025-02-23T12:27:33.001603+00:00
2025-02-23T12:27:33.001603+00:00
4
false
# Approach <!-- Describe your approach to solving the problem. --> Actually we do not need to convert each number in the array into a string and then iterate through the string to get the sum of the digits as Hint 1 implies. Instead what we can do is iterate through each number in the array. We then perform the following operation: - take the number % 10 to get the first digit of the number - then divide the number by 10 since we want to get the next digits in the number in following iterations - and then add the digit to a variable you assigned outside the iteration like "sum" - continue these operations until the number < 0 Ofcourse after we did these operations we then check if we saw a sum of digits that was smaller or if the sum that we just computed is infact the smallest, since we do need to return the minmum sum of digits in the array. # Time Complexity O(n * m) n: length of array m: amount of digits in num # Code ```java [] class Solution { public int minElement(int[] nums) { int minElem = Integer.MAX_VALUE; for (Integer num : nums) { int sum = 0; while (num > 0) { int digit = num % 10; num /= 10; sum += digit; } minElem = minElem > sum ? sum : minElem; } return minElem; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
basic JS solution
basic-js-solution-by-dhcp-1zrz
Code
dhcp
NORMAL
2025-02-20T22:37:47.411856+00:00
2025-02-20T22:37:47.411856+00:00
6
false
# Code ```javascript [] /** * @param {number[]} nums * @return {number} */ let minElement = (a) => { return Math .min(...a .map(i => { return [...`${i}`] .reduce((q, w) => eval(q) + eval(w), 0); })); }; ```
0
0
['JavaScript']
0
minimum-element-after-replacement-with-digit-sum
Beats 100
beats-100-by-manoranjani_selvakumar-as03
class Solution {public int minElement(int[] nums) {Listlis=new ArrayList<>();for(int i=0;i<nums.length;i++){int ans=0;int val=nums[i];while(val!=0){int rem=val%
manoranjani_selvakumar
NORMAL
2025-02-19T13:52:30.030122+00:00
2025-02-19T13:52:30.030122+00:00
2
false
class Solution { public int minElement(int[] nums) { List<Integer>lis=new ArrayList<>(); for(int i=0;i<nums.length;i++){ int ans=0; int val=nums[i]; while(val!=0){ int rem=val%10; ans+=rem; val=val/10; } lis.add(ans); } int min=Integer.MAX_VALUE; for(int fin:lis){ if(fin<min){ min=fin; } } return min; } } ```
0
0
['Java']
0
minimum-element-after-replacement-with-digit-sum
oneliner: min(sum(int(d)for d in str(v))for v in nums)
oneliner-minsumintdfor-d-in-strvfor-v-in-d43l
null
qulinxao
NORMAL
2025-02-19T11:14:13.179187+00:00
2025-02-19T11:14:13.179187+00:00
2
false
```python3 [] class Solution: def minElement(self, nums: List[int]) -> int: return min(sum(int(d)for d in str(v))for v in nums) ```
0
0
['Python3']
0
find-valid-emails
pandas || no regex... ||
pandas-no-regex-by-spaulding-qaq4
... because I don't like regex.
Spaulding_
NORMAL
2025-01-29T23:08:40.332769+00:00
2025-01-31T18:22:09.290809+00:00
449
false
... because I don't like regex. ```pythondata [] import pandas as pd def find_valid_emails(users: pd.DataFrame) -> pd.DataFrame: def is_valid(x: str)-> bool: s = x['email'].split('@') if len(s) != 2: return False # check for exactly one '@' pref, suff = s # check whether underscore is the pref.replace('_', '') # only non-alpha in prefix return all( (pref.isalpha, # check whether prefix is alpha suff[:-4].isalpha(), # check whether suffix starts with alpha suff.endswith('.com')) ) # check whether suffix ends with '.com' return users[users.apply(is_valid, axis=1)].sort_values(['user_id']) ```
13
0
['Pandas']
1
find-valid-emails
Elegant & Short | Pandas vs SQL | Simple RegEx
elegant-short-pandas-vs-sql-by-kyrylo-kt-dzqz
null
Kyrylo-Ktl
NORMAL
2025-01-30T09:32:19.366121+00:00
2025-01-30T09:42:41.854204+00:00
1,959
false
```PostgreSQL [] SELECT user_id, email FROM users WHERE email ~ '^\w+@\w+\.com$' ORDER BY user_id; ``` ```MySQL [] SELECT user_id, email FROM users WHERE regexp_like(email, '[a-zA-Z0-9_]+@[a-zA-Z0-9_]+\.com$') ORDER BY user_id; ``` ```Oracle [] SELECT user_id, email FROM users WHERE regexp_like(email, '^[[:alnum:]_]+@[[:alnum:]]+\.com$') ORDER BY user_id; ``` ```Python [] def find_valid_emails(users: pd.DataFrame) -> pd.DataFrame: valid_emails = users[users['email'].str.match(r'^\w+@\w+\.com$', na=False)] valid_emails = valid_emails.sort_values(by='user_id') return valid_emails ```
5
0
['Python3', 'MySQL', 'Oracle', 'PostgreSQL', 'Pandas']
3
find-valid-emails
Simple Solution || Why Overcomplicate
simple-solution-why-overcomplicate-by-vi-oc9x
IntuitionWe need to find valid email addresses based on certain criteria: Exactly one @ symbol. Ends with .com. The part before the @ symbol contains only alpha
Vipul_05_Jain
NORMAL
2025-02-10T05:54:25.497469+00:00
2025-02-10T05:54:25.497469+00:00
950
false
# Intuition We need to find valid email addresses based on certain criteria: 1. Exactly one @ symbol. 2. Ends with .com. 3. The part before the @ symbol contains only alphanumeric characters and underscores. 4. The domain part (between @ and .com) contains only letters. # Approach 1. Use REGEXP: To match the email pattern using regular expressions. ^[a-zA-Z0-9_]+@[a-zA-Z]+\.com$ ensures the local part has only alphanumeric characters and underscores, the domain has only letters, and it ends with .com. 2. Return valid emails and order by user_id. # Code ```mysql [] # Write your MySQL query statement below SELECT * FROM Users WHERE REGEXP_LIKE(email, '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com) ``` # PLEASE UPVOTE FOR MORE SUCH SOLUTIONS...
3
0
['MySQL']
1
find-valid-emails
Why complicate?
why-complicate-by-ankush1493-y3o6
Code
ankush1493
NORMAL
2025-01-30T06:18:10.395618+00:00
2025-01-30T06:18:10.395618+00:00
561
false
# Code ```postgresql [] -- Write your PostgreSQL query statement below SELECT user_id , email FROM Users WHERE email LIKE '%@%.com'; ```
3
0
['PostgreSQL']
3
find-valid-emails
SQL solutions - regular expressions
sql-solutions-regular-expressions-by-ada-8om8
Fun with regular expressions! The fact that this question deals with character "types," i.e., alphanumeric, letter, etc., is an indicator that regular expressi
adamrbeier
NORMAL
2025-01-29T21:42:41.777249+00:00
2025-01-30T17:16:59.798770+00:00
919
false
Fun with regular expressions! The fact that this question deals with character "types," i.e., alphanumeric, letter, etc., is an indicator that regular expressions are the key here. There was a question about regular expressions a handful of weeks ago ([3415. Find Products with Three Consecutive Digits](https://leetcode.com/problems/find-products-with-three-consecutive-digits/description/)), so tackling that, along with familiarizing yourself with regular expressions, would be a good place to start. This problem here had the "Easy" label but I thought it did have some tricky components. Let's dive into how to tackle this one... # Approach Some quick notes here that'll add up to the solution: \- SQL doesn't have a great "count instances of character in string" so use `length(<raw field>) - length(replace(<raw field>, '<character>', ''))` to do that. Here the character is the @ symbol, and there should be one and only one in the email. \- Use `instr()` (Oracle, MySQL), `charindex()` (MSSQL), or `position()` to get the character position of that single @ (examine the solution code for more specifics on the differences between each variant). Let's call that position "at_pos" (I do not use that alias in the code but it makes the below easier to explain): \-\- Take `substr`/`substring(email, 1, at_pos - 1)` to get the characters before the @, and I also apply uppercase to make the character matching easier. Perform regular expression **not like** `[^A-Z0-9]`, meaning that the string cannot contain a character that is both non-alpha (A-Z) and non-digit (0-9). \-\- Take `substr`/`substring(email, at_pos + 1, 1)` to get the character directly after the @, and I also apply uppercase once again. Perform regular expression **like** `[A-Z]`, as the first character after the @ must be a letter. \- Since the domain after the @ must end in ".com", perform a simple `like '%.COM'` Put those 4 conditions together and that'll yield valid emails. Note that each SQL variant handles "invalid" substring arguments differently, such as negative indices or indices of 0; this solution performs the substring based on the position of the @ and I found MSSQL and Postgres to require valid substring arguments (that result in an actual substring) as opposed to Oracle and MySQL which accepted arguments that didn't result in a valid substring. That's why you'll see a CTE used for the former 2, and the CTE filters emails to only those that have an @. # Code ```Oracle [] /* Write your PL/SQL query statement below */ select user_id, email from Users where (LENGTH(email) - LENGTH(REPLACE(email, '@', ''))) = 1 and not REGEXP_LIKE(upper(substr(email, 1, instr(email, '@') - 1)), '[^A-Z0-9]') and REGEXP_LIKE(upper(substr(email, instr(email, '@') + 1, 1)), '[A-Z]') and upper(email) like '%.COM'; ``` ```MySQL [] # Write your MySQL query statement below select user_id, email from Users where (LENGTH(email) - LENGTH(REPLACE(email, '@', ''))) = 1 and not REGEXP_LIKE(upper(substr(email, 1, instr(email, '@') - 1)), '[^A-Z0-9]') and REGEXP_LIKE(upper(substr(email, instr(email, '@') + 1, 1)), '[A-Z]') and upper(email) like '%.COM'; ``` ```MSSQL [] /* Write your T-SQL query statement below */ with users_valid_at as (select user_id, email from Users where (LEN(email) - LEN(REPLACE(email, '@', ''))) = 1) select user_id, email from users_valid_at where not upper(substring(email, 1, charindex('@', email) - 1)) like '[^A-Z0-9]' and upper(substring(email, charindex('@', email) + 1, 1)) like '[A-Z]' and upper(email) like '%.COM' ``` ```Postgres [] -- Write your PostgreSQL query statement below with users_valid_at as (select user_id, email from Users where (LENGTH(email) - LENGTH(REPLACE(email, '@', ''))) = 1) select user_id, email from users_valid_at where not REGEXP_LIKE(upper(substr(email, 1, greatest(position('@' in email) - 1, 1))), '[^A-Z0-9]') and REGEXP_LIKE(upper(substr(email, position('@' in email) + 1, 1)), '[A-Z]') and upper(email) like '%.COM'; ```
3
1
['MySQL', 'Oracle', 'MS SQL Server', 'PostgreSQL']
1
find-valid-emails
[MySQL|Pandas] regex
mysqlpandas-regex-by-ye15-sdyp
IntuitionApproachComplexity Time complexity: Space complexity: Code
ye15
NORMAL
2025-01-29T21:22:28.872271+00:00
2025-01-29T21:22:28.872271+00:00
203
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```pythondata [] import pandas as pd def find_valid_emails(users: pd.DataFrame) -> pd.DataFrame: return users.query( expr = "email.str.match(r'^\w*@[a-zA-Z].*\.com$')" ).sort_values( by = "user_id" ) ``` ```MySQL [] SELECT * FROM Users WHERE email REGEXP '^[:word:]*@[a-zA-Z].*\.com' ORDER BY 1 ```
3
1
['Pandas']
0
find-valid-emails
REGEXP solution
regexp-solution-by-vicolada26-9fwv
Intuition^ – beginning of the string[a-zA-Z0-9_]* - symbols that we can use before @ ; 0+ accurances[a-zA-Z] - symbols we can use after @ ; 0+ accurances. - esc
vicolada26
NORMAL
2025-02-05T22:32:58.415375+00:00
2025-02-05T22:32:58.415375+00:00
154
false
# Intuition ^ – beginning of the string [a-zA-Z0-9_]* - symbols that we can use before @ ; 0+ accurances [a-zA-Z] - symbols we can use after @ ; 0+ accurances \. - escaping special character . $ - end of the string # Code ```mysql [] SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]*@[a-zA-Z]*\.com$' ORDER BY user_id ```
2
0
['MySQL']
0
find-valid-emails
Easy to understand
easy-to-understand-by-amoghamayya-9n4j
IntuitionThe goal is to filter valid email addresses ending in .com. Regular expressions (~ operator) help match a structured pattern. Sorting by user_id ensure
AmoghaMayya
NORMAL
2025-01-30T16:46:33.781856+00:00
2025-01-30T16:46:33.781856+00:00
243
false
# Intuition The goal is to filter valid email addresses ending in .com. Regular expressions (~ operator) help match a structured pattern. Sorting by user_id ensures a consistent order in results. ^ → Start of string. [a-zA-Z0-9]+ → Username with letters and digits. @ → Mandatory @ symbol. [a-zA-Z]+ → Domain name with only letters. \.com$ → Ends with .com. # Code ```postgresql [] select * from users where email ~ '^[a-zA-Z0-9]+@[a-zA-Z]+\.com$' order by user_id; ```
2
0
['PostgreSQL']
1
find-valid-emails
MySQL Easy Solution
mysql-easy-solution-by-heyysankalp-rfif
IntuitionThe task is to filter valid emails from the Users table using a regular expression (REGEXP). A valid email in this context should: Start with alphanum
heyysankalp
NORMAL
2025-04-08T14:19:24.510898+00:00
2025-04-08T14:19:24.510898+00:00
55
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The task is to filter valid emails from the Users table using a regular expression (REGEXP). A valid email in this context should: - Start with alphanumeric characters or underscores ([a-zA-Z0-9_]+) - Be followed by @ - Then only alphabet characters ([a-zA-Z]+) - End with .com # Approach <!-- Describe your approach to solving the problem. --> Use the REGEXP operator in SQL to define a pattern for valid emails: 1. Start (^) with one or more alphanumeric or underscore characters. 2. Then an @ symbol. 3. Followed by one or more letters. 4. Finally ends with .com using \.com$. # Complexity - Time complexity:O(n) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity:O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com ``` ```
1
0
['Database', 'MySQL']
0
find-valid-emails
🔥🔥 2 Solutions in MySQL | Beats 96.63%🔥🔥
2-solutions-in-mysql-beats-9663-by-prito-4mqb
💡 Solution 1: Using REGEX, SUBSTR(), LIKE & LOCATE() - Beats 96.63%💡 Intuition🔍 The task is to filter valid email addresses from a table. My initial thought was
pritom5928
NORMAL
2025-04-07T11:02:39.143910+00:00
2025-04-07T11:02:39.143910+00:00
56
false
# 💡 Solution 1: Using REGEX, SUBSTR(), LIKE & LOCATE() - Beats 96.63% # 💡 Intuition 🔍 The task is to filter valid email addresses from a table. My initial thought was: We’re looking for: ✅ A username (before @) with only letters, numbers, and _. ✅ A domain name (after @) containing only letters. ✅ A domain that ends with .com. # 🧠 Approach We break down the email into parts using LOCATE() and SUBSTR() functions and validate them using REGEXP: 1. 🔗 **Structure Check**: email LIKE '%@%.com' ensures the format is close to [email protected]. 2. ✍️ **Username Validation**: SUBSTR(email, 1, LOCATE('@', email) - 1) 3. 🌐 **Domain Validation**: SUBSTR(email, LOCATE('@', email) + 1, LENGTH(email) - LOCATE('@', email) - 4) 4. 🧹 **Sorting**: We use ORDER BY user_id for a clean and predictable result. # 📊 Complexity - ⏱ Time complexity: **O(n*m)** Where n is the number of users and m is the average email length due to string manipulation and regex matching. - 🧠 Space complexity: **O(n)** # Code ```mysql [] SELECT * FROM users WHERE email LIKE '%@%.com' AND SUBSTR(email, 1, LOCATE('@', email) - 1) REGEXP '^[a-zA-Z0-9_]+$' AND SUBSTR(email, LOCATE('@', email) + 1, LENGTH(email) - LOCATE('@', email) - 4) REGEXP '^[a-zA-Z]+$' ORDER BY user_id; ``` # 💡 Solution 2: Using REGEX only - Beats 5.51% # 💡 Intuition 🔍 The goal is to filter out emails that are valid based on a strict pattern: ✅ The local part (before @) contains only alphanumeric characters and underscores. ✅ The domain contains only alphabetic characters. ✅ The email ends with .com. Using a single regular expression, we can match the entire structure of the email without breaking it down manually. # 🧠 Approach ``` 1. Regex Match: The regex '^[a-zA-Z0-9_]+@[a-zA-Z]+.(com)$' does the following 2. ^[a-zA-Z0-9_]+ → ensures the local part starts at the beginning and has only valid characters. 3. @ → ensures presence of a single @. 4. [a-zA-Z]+ → validates domain name (only letters). 5. .(com)$ → ensures it ends with .com. ``` # 📊 Complexity ⏱ Time Complexity: **𝑂(𝑛*𝑚)** Where n is the number of rows in the users table, and m is the length of the email string (due to regex evaluation). 🧠 Space Complexity: **O(n)** auxiliary memory in most engines # Code ```mysql [] SELECT * FROM users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+.(com)$' ORDER BY user_id; ```
1
0
['Database', 'MySQL']
0
find-valid-emails
using regular expression
using-regular-expression-by-rasitha7-otof
Code
BangtanBits
NORMAL
2025-03-03T12:54:46.251283+00:00
2025-03-03T12:55:28.799318+00:00
232
false
# Code ```mysql [] # Write your MySQL query statement below select user_id, email from users where email regexp '^[A-Za-z0-9]+@[A-Za-z]+\\.com order by user_id; ```
1
0
['MySQL']
0
find-valid-emails
<<MOST EASY SOLUTION>>
most-easy-solution-by-dakshesh_vyas123-j91b
PLEASE UPVOTE MECode
Dakshesh_vyas123
NORMAL
2025-02-23T15:51:01.113940+00:00
2025-02-23T15:51:01.113940+00:00
303
false
# **PLEASE UPVOTE ME** # Code ```mysql [] # Write your MySQL query statement below select user_id,email from Users where email like '%@%.com' and email not like '%.%@%.com' ```
1
0
['MySQL']
2
find-valid-emails
☑️ Finding Valid Emails.☑️
finding-valid-emails-by-abdusalom_16-9azk
Code
Abdusalom_16
NORMAL
2025-02-07T04:31:28.038189+00:00
2025-02-07T04:31:28.038189+00:00
280
false
# Code ```postgresql [] select * from Users where email ~ '^[0-9a-zA-Z_]+@[a-zA-Z]+\.com ```; ```
1
0
['Database', 'MySQL', 'PostgreSQL']
0
find-valid-emails
Easy to understand using Wildcard
easy-to-understand-using-wildcard-by-dar-m1lh
Bold# IntuitionApproachComplexity Time complexity: Space complexity: Code
darwadenidhi174
NORMAL
2025-02-06T08:58:57.121214+00:00
2025-02-06T08:58:57.121214+00:00
210
false
******Bold******# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below select * from Users where email LIKE '%@%.com'; ```
1
0
['MySQL']
2
find-valid-emails
AVS
avs-by-vishal1431-q3k9
null
Vishal1431
NORMAL
2025-02-05T18:18:31.908569+00:00
2025-02-05T18:18:31.908569+00:00
86
false
```mysql [] SELECT user_id, email FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com ORDER BY user_id ASC; ```
1
0
['MySQL']
0
find-valid-emails
Easy MySQL solution
easy-mysql-solution-by-harsh_indoria-1ab4
IntuitionThe problem requires extracting valid email addresses from a database. We need to ensure that the email format follows strict criteria: It contains exa
HARSH_INDORIA
NORMAL
2025-02-05T17:15:01.667184+00:00
2025-02-05T17:15:01.667184+00:00
255
false
# **Intuition** The problem requires extracting valid email addresses from a database. We need to ensure that the email format follows strict criteria: - It contains exactly **one `@` symbol**. - It **ends with `.com`**. - The **username (before `@`)** consists of only **alphanumeric characters and underscores**. - The **domain name (between `@` and `.com`)** consists of only **letters**. --- # **Approach** 1. **Use `LIKE '%.com'` to filter `.com` emails first** - This is a **faster operation** compared to `REGEXP`, as it avoids scanning unnecessary records. 2. **Apply `REGEXP` for strict email validation** - Ensure the **username** (`^[a-zA-Z0-9_]+`) contains only alphanumeric characters and underscores. - Ensure the **domain name** (`[a-zA-Z]+`) consists of only **letters**. - Escape the dot (`\\.com$`) to match the `.com` ending. --- # **Code** ```mysql SELECT user_id, email FROM Users WHERE email LIKE '%.com' AND email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com$' ORDER BY user_id; ```
1
0
['Database', 'MySQL']
0
find-valid-emails
NO REGEX FUNCTIONS
no-regex-functions-by-alitharwat-n1el
Intuition1st part consists of: ....................................... lowercase letters : a-z ....................................... uppercase letters : A-Z .
alitharwat
NORMAL
2025-02-01T18:21:59.524890+00:00
2025-04-02T11:44:07.787558+00:00
459
false
# Intuition 1st part consists of: ....................................... lowercase letters : a-z ....................................... uppercase letters : A-Z ....................................... digits : 0-9 ....................................... underscore : _ 2nd part is : @ 3rd part consists of : ....................................... lowercase letters : a-z ....................................... uppercase letters : A-Z 4th part is : .com # Approach 1- check that only 1 '@' exists 2- check that it ends with '.com' 3- check that the 1st part is not anything but a letter, number or underscore 4- check that the 3rd part is not anything but letters 5- order/sort by the user_id # Code ```MSSQL [] SELECT user_id , email FROM Users WHERE email LIKE '[a-zA-Z0-9_]%@[a-zA-Z]%.com' AND email NOT LIKE '%..%' AND email NOT LIKE '%.%@%' AND email NOT LIKE '%@[a-zA-Z]%[0-9]%' ORDER BY user_id ``` ```Python [] import pandas as pd def find_valid_emails(users: pd.DataFrame) -> pd.DataFrame: def is_valid_email(email): if email.count("@") != 1: return False if not email.endswith(".com"):return False a , domain = email.split("@") if not all(c.isalnum()or c =="_" for c in a): return False domain_name = domain[:-4] #domain but excluding '.com' if not domain_name.isalpha(): return False return True valid = users[users["email"].apply(is_valid_email)] return valid.sort_values(by="user_id")[["user_id", "email"]] ```
1
0
['String', 'MS SQL Server', 'Pandas']
2
find-valid-emails
!!! NON-RegEx simple UNIVERSAL database solution !!!
fast-simple-portable-solution-without-re-0efk
ApproachSince - unlike RegEx - LIKE does not support []+ and []* constructs, there are two LIKE parts: first one includes "positive" restrictions - i.e. parts w
fAYmP5Fcs3
NORMAL
2025-01-31T23:30:55.405843+00:00
2025-02-24T20:59:40.455175+00:00
96
false
# Approach Since - unlike RegEx - LIKE does not support []+ and []* constructs, there are two LIKE parts: first one includes "positive" restrictions - i.e. parts we want to match; second one includes "negative" restrictions - i.e. what we do not want to match. A fast solution that only uses standard LIKE clause, and will work for all databases without requring DB-specific modifications, or use of special libraries for RegEx functionality. # Code ```mssql [] select * from Users where email like '%@%.com' and email not like '%[^0-9A-Za-z_]%@%[^0-9A-Za-z]%' order by user_id ```
1
1
['Database', 'MySQL', 'Oracle', 'MS SQL Server', 'PostgreSQL']
0
find-valid-emails
Regex solution
regex-solution-by-manasa_bitla-wbv7
IntuitionApproachComplexity Time complexity: Space complexity: Code
manasa_bitla
NORMAL
2025-04-11T16:43:43.516254+00:00
2025-04-11T16:43:43.516254+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```postgresql [] -- Write your PostgreSQL query statement below SELECT user_id , email FROM Users WHERE email ~ '^[a-z,A-Z,0-9,_]+@[a-z,A-Z]+.com ``` ```
0
0
['PostgreSQL']
0
find-valid-emails
Find Valid Emails || Using regular expressions
find-valid-emails-using-regular-expressi-jbaj
IntuitionApproachComplexity Time complexity: Space complexity: Code
Shruttz
NORMAL
2025-04-10T19:06:12.478928+00:00
2025-04-10T19:06:12.478928+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below # Write your MySQL query statement below SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com' ```
0
0
['Database', 'MySQL']
0
find-valid-emails
My solution
my-solution-by-srs_ua-3qmk
IntuitionApproachComplexity Time complexity: Space complexity: CodeORDER BY user_id
SRS_UA
NORMAL
2025-04-06T17:54:21.657511+00:00
2025-04-06T17:54:21.657511+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```postgresql [] SELECT * FROM Users WHERE email ~'^[a-zA-Z0-9_]+@[a-zA-z]+\.[cC][oO][mM] ``` ORDER BY user_id ```
0
0
['PostgreSQL']
0
find-valid-emails
Easy Solutin using Regexp
easy-solutin-using-regexp-by-adhi_m_s-ua8h
IntuitionApproachComplexity Time complexity: Space complexity: Code
Adhi_M_S
NORMAL
2025-04-05T04:10:18.720599+00:00
2025-04-05T04:10:18.720599+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] select * from Users where email regexp '^[a-zA-Z0-9_]*@[a-zA-Z]*\.com' ```
0
0
['MySQL']
0
find-valid-emails
Simple and Easy Beginner Friendly Code using RegExp
simple-and-easy-beginner-friendly-code-u-27w3
IntuitionMy first thought is to filter the Users table to select only those rows where the email address matches a specific pattern. This pattern appears to be
Balarakesh
NORMAL
2025-04-04T18:34:34.954731+00:00
2025-04-04T18:34:34.954731+00:00
1
false
# Intuition My first thought is to filter the `Users` table to select only those rows where the `email` address matches a specific pattern. This pattern appears to be checking for a basic `.com` email format. # Approach 1. **Select all columns:** The `SELECT *` clause indicates that we want to retrieve all columns from the `Users` table. 2. **Filter rows based on email pattern:** The `WHERE` clause is used to apply a condition to filter the rows. 3. **Use regular expression matching:** The `REGEXP_LIKE` function (which might vary slightly depending on the specific MySQL version or configuration, sometimes it's `RLIKE` or just `email REGEXP`) is used to check if the `email` column matches the provided regular expression. 4. **Define the regular expression:** The regular expression `'^[a-zA-Z0-9_]+@[a-zA-Z]+\.com'` is used to define the desired email format: - `^`: Matches the beginning of the string. - `[a-zA-Z0-9_]+`: Matches one or more alphanumeric characters (uppercase or lowercase) or underscores. This part likely represents the username. - `@`: Matches the "@" symbol. - `[a-zA-Z]+`: Matches one or more uppercase or lowercase alphabetic characters. This part likely represents the domain name. - `\.`: Matches a literal dot ".". The backslash is used to escape the special meaning of the dot in regular expressions. - `com`: Matches the literal string "com". - `$`: Matches the end of the string (although it's missing in the provided code snippet, it's generally a good practice to include it for a complete match). **Note:** The provided code snippet has a syntax error because the closing single quote for the regular expression is missing. The corrected code will include this. # Complexity - Time complexity: $$O(n \cdot m)$$ - Where 'n' is the number of rows in the `Users` table and 'm' is the average length of the `email` string. In the worst case, the regular expression engine might need to examine each character of the email for every row. However, database systems often have optimized implementations for regular expression matching. - Space complexity: $$O(1)$$ - The query performs filtering in place and doesn't require significant extra space proportional to the input size. The space used is mainly for storing the result set, which depends on the number of matching rows. # Code ```sql SELECT * FROM Users WHERE REGEXP_LIKE(email, '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com$');
0
0
['MySQL']
0
find-valid-emails
BEAT 93.77% SIMPLE REGEX SOLUTION
beat-9377-simple-regex-solution-by-egors-2rty
Code
egorsavonchik1
NORMAL
2025-04-03T09:11:52.533302+00:00
2025-04-03T09:11:52.533302+00:00
4
false
![image.png](https://assets.leetcode.com/users/images/060a635d-313b-41f5-9124-ae47c94401e4_1743671491.3640473.png) # Code ```postgresql [] SELECT * FROM Users WHERE email ~ '^\w+@[a-zA-Z]+\.com; ```
0
0
['PostgreSQL']
0
find-valid-emails
Using Regex
using-regex-by-venkatarohit_p-e24i
IntuitionApproachComplexity Time complexity: Space complexity: Code
venkatarohit_p
NORMAL
2025-04-02T08:59:31.892661+00:00
2025-04-02T08:59:31.892661+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below Select * from users where regexp_like(email,'^[a-zA-Z0-9]+@[a-zA-Z]+\.com') ```
0
0
['MySQL']
0
find-valid-emails
Validating email in SQL
validating-email-in-sql-by-aadarshsenapa-jnp4
IntuitionDisplay the user id and email id so we need to project user id and email.ApproachTo validate email id we need to use the regular expressions. It can be
aadarshsenapati
NORMAL
2025-04-02T03:31:46.517605+00:00
2025-04-02T03:31:46.517605+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Display the user id and email id so we need to project user id and email. # Approach <!-- Describe your approach to solving the problem. --> To validate email id we need to use the regular expressions. It can be done by using REGEXP along with where condition. # Complexity - Time complexity: $$O(n*log(n)$$) <!-- Add your time complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below SELECT user_id, email FROM Users WHERE email REGEXP '^[A-Za-z0-9_]+@[A-Za-z][A-Za-z]*\\.com ``` order by user_id; ```
0
0
['MySQL']
0
find-valid-emails
MySQL solution with REGEXP, REGEXP_LIKE
mysql-solution-with-regexp-regexp_like-b-hyua
IntuitionApproachComplexity Time complexity: Space complexity: Code
yukikitayama
NORMAL
2025-04-01T12:57:24.389632+00:00
2025-04-01T12:57:24.389632+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below SELECT * FROM Users WHERE -- Same -- email REGEXP '^[a-zA-Z0-9_]+@{1}[a-zA-Z]+\.com REGEXP_LIKE(email, '^[a-zA-Z0-9_]+@{1}[a-zA-Z]+\.com) ORDER BY user_id ```
0
0
['MySQL']
0
find-valid-emails
Beats 90% simple easy to understand three steps
beats-90-simple-easy-to-understand-three-4d6c
Intuition Starts with alphanumeric number ^[a-zA-Z0-9_]{1,} before .com only alphabets [a-zA-Z]{1,} ends with .com .com$ Code
djassie
NORMAL
2025-03-31T13:19:12.940670+00:00
2025-03-31T13:19:12.940670+00:00
4
false
![Screenshot 2025-03-31 183925.png](https://assets.leetcode.com/users/images/05261ff7-dd0b-4952-aab6-30c607b30480_1743427145.868411.png) # Intuition 1. Starts with alphanumeric number `^[a-zA-Z0-9_]{1,}` 2. before **.com** only alphabets `[a-zA-Z]{1,}` 3. ends with **.com** `.com$` # Code ```mysql [] SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]{1,}@[a-zA-Z]{1,}.com$' ORDER BY user_id ASC; ```
0
0
['MySQL']
0
find-valid-emails
Beats 90% simple easy to understand three steps
beats-90-simple-easy-to-understand-three-k069
Intuition Starts with alphanumeric number ^[a-zA-Z0-9_]{1,} before .com only alphabets [a-zA-Z]{1,} ends with .com .com$ Code
djassie
NORMAL
2025-03-31T13:13:41.653335+00:00
2025-03-31T13:13:41.653335+00:00
3
false
# Intuition 1. Starts with alphanumeric number `^[a-zA-Z0-9_]{1,}` 2. before **.com** only alphabets `[a-zA-Z]{1,}` 3. ends with **.com** `.com$` # Code ````sql SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]{1,}@[a-zA-Z]{1,}.com$' ORDER BY user_id ASC; ````
0
0
['MySQL']
0
find-valid-emails
MySQL SOLUTION | Beats 90.29% RUNTIME | EASY INTUTIVE SOLUTION |RegExp
mysql-solution-beats-9029-runtime-easy-i-4flg
Complexity Time complexity : O(N) Space complexity : O(1) CodeORDER BY user_id;
SrinithyaThiyagarajan
NORMAL
2025-03-29T16:34:18.090695+00:00
2025-03-29T16:34:18.090695+00:00
6
false
# Complexity - Time complexity : O(N) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity : O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below SELECT * FROM users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com ``` ORDER BY user_id; ```
0
0
['MySQL']
0
find-valid-emails
VERY EASY ORACLE SQL SOLUTION!!!
very-easy-oracle-sql-solution-by-timothy-d26w
IntuitionApproachComplexity Time complexity: Space complexity: Code
timothytkim
NORMAL
2025-03-27T04:00:06.769482+00:00
2025-03-27T04:00:06.769482+00:00
8
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```oraclesql [] /* Write your PL/SQL query statement below */ SELECT * FROM Users WHERE REGEXP_LIKE(email, '^[A-Za-z0-9_]+@[A-Za-z]+\.com ```); ```
0
0
['Oracle']
0
find-valid-emails
Most solutions here are missing the latest testcase no 13 of "number in the domain" | Updated sol
most-solutions-here-are-missing-the-late-766n
The testcase 13 says that the test cases where the domain name contains numbers (e.g., [email protected],[email protected])I have reported the missing tes
somyansh
NORMAL
2025-03-25T07:55:04.870936+00:00
2025-03-25T07:55:04.870936+00:00
11
false
# The testcase 13 says that the test cases where the domain name contains numbers (e.g., [email protected],[email protected]) **I have reported the missing test case myself on the leetcode platform. So here is the updated code which runs all test cases** # Intuition This query selects users with properly formatted .com email addresses. It first checks that the email contains exactly one @ symbol and ends with .com. Then, it ensures the username (the part before @) contains only letters and numbers, meaning no special characters like !, _, or #. Finally, it verifies that the domain name (the part between @ and .com) consists of only letters, ensuring there are no numbers or special symbols. This helps filter out incorrectly formatted emails and keeps the data clean. # Code ```mssql [] SELECT * FROM users WHERE -- Ensure the email contains exactly one '@' symbol LEN(email) - LEN(REPLACE(email, '@', '')) = 1 -- Ensure the email ends with '.com' AND email LIKE '%.com' -- Ensure the part before '@' (username) contains only letters and numbers AND LEFT(email, CHARINDEX('@', email) - 1) NOT LIKE '%[^a-zA-Z0-9]%' -- Ensure the domain name (between '@' and '.com') contains only letters AND SUBSTRING(email, CHARINDEX('@', email) + 1, CHARINDEX('.com', email) - CHARINDEX('@', email) - 1) NOT LIKE '%[^a-zA-Z]%'; ```
0
0
['MS SQL Server']
0
find-valid-emails
MySQL Query
mysql-query-by-kundusomnath610-dyur
IntuitionApproachTry RegEX_Like ExpressionComplexity Time complexity: Space complexity: Code
kundusomnath610
NORMAL
2025-03-23T07:59:37.538165+00:00
2025-03-23T07:59:37.538165+00:00
8
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> Try RegEX_Like Expression # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] SELECT user_id, email FROM users WHERE regexp_like(email, '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com ```) ORDER BY user_id; ```
0
0
['MySQL']
0
find-valid-emails
MYSQL FREE QUESTION LEETCODE
mysql-free-question-leetcode-by-anything-prme
IntuitionApproachComplexity Time complexity: Space complexity: Codeand subs2 REGEXP '[a-zA-Z]*
anythingFORSQL
NORMAL
2025-03-19T15:22:13.971243+00:00
2025-03-19T15:22:13.971243+00:00
10
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below with cte as( select Users.*,LOCATE('@',email) as r1,LOCATE('@',email,LOCATE('@',email)) as r2 FROM Users where LOCATE('@',email,LOCATE('@',email))!=0 and email LIKE '%.com' ),cte1 as( select cte.*,SUBSTRING(email,1,r1-1) as subs1,SUBSTRING(email,r1+1,LENGTH(email)-r1-4) as subs2 FROM cte ) select user_id,email FROM cte1 where subs1 REGEXP '^[a-zA-Z0-9-]* ``` and subs2 REGEXP '[a-zA-Z]* ```; ```
0
0
['MySQL']
0
find-valid-emails
Use Either Regexp or Regexp_like() || Given both solutions || MySQL :
use-either-regexp-or-regexp_like-given-b-od9c
Code 1Code 2
AmanSingh279
NORMAL
2025-03-19T04:32:43.544748+00:00
2025-03-19T04:48:03.810816+00:00
6
false
# Code 1 ``` select user_id , email from Users where email regexp '^[A-Za-z0-9][A-Za-z0-9_]*@[A-Za-z]*[.]com$' ``` # Code 2 `````` select user_id , email from Users where regexp_like(email , '^[A-Za-z0-9][A-Za-z0-9_]*@[A-Za-z]*[.]com$')
0
0
['MySQL']
0
find-valid-emails
PostgreSQL regex solution | clearly explained
postgresql-regex-solution-clearly-explai-upwc
IntuitionUse Regex to match patternsApproach~: like^: starts with-: represent range between letters or numbers, e.g., a-zA-Z0-9+: match the pattern [_a-zA-Z0-9]
echoxiao
NORMAL
2025-03-18T03:07:42.744065+00:00
2025-03-18T03:07:42.744065+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Use Regex to match patterns # Approach <!-- Describe your approach to solving the problem. --> `~`: like `^`: starts with `-`: represent range between letters or numbers, e.g., `a-zA-Z0-9` `+`: match the pattern `[_a-zA-Z0-9]` 1 or more times. must match the pattern `\.`: escape and interpret `.` as a character. otherwise, the regex engine interprets it as "match any character" `$`: mark the pattern's end, so no extra character is allowed after `$` `*`: match the pattern 0, 1 or more times. It allows characters that do not match the pattern # Note Use `^[_a-zA-Z0-9]+` instead of `[_a-zA-Z0-9]*` since `*` allows characters that do not match the pattern. For example, `!./@aa.com` could match the pattern `[_a-zA-Z0-9]*@[a-zA-Z]*\.com$` since `*` allows 0 match from substring `!./` to the sub pattern `[_a-zA-Z0-9]`. # Code ```postgresql [] -- Write your PostgreSQL query statement below select user_id, email from Users where email ~ '^[_a-zA-Z0-9]+@[a-zA-Z]*\.com$' order by user_id ```
0
0
['PostgreSQL']
0
find-valid-emails
Mysql solution
mysql-solution-by-hari1371999-ca0u
IntuitionApproachComplexity Time complexity: Space complexity: Code
hari1371999
NORMAL
2025-03-07T04:23:35.511195+00:00
2025-03-07T04:23:35.511195+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] select * from Users where email REGEXP '^[A-Za-z0-9_]+@[A-za-z]+.com'; ```
0
0
['MySQL']
0
find-valid-emails
Find Valid Emails
find-valid-emails-by-rakshrao-d7oi
IntuitionApproachComplexity Time complexity: Space complexity: Code
rakshrao
NORMAL
2025-03-06T17:52:30.506881+00:00
2025-03-06T17:52:30.506881+00:00
7
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below -- select user_id, email -- from Users -- where email like '[0-9a-zA-Z._%+-]+@[a-zA-Z].com' SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com ```; ```
0
0
['MySQL']
0
find-valid-emails
MySQL Straightforward Solution
mysql-straightforward-solution-by-cureno-dmua
Code
curenosm
NORMAL
2025-03-06T13:06:17.758983+00:00
2025-03-06T13:06:17.758983+00:00
4
false
# Code ```mysql [] SELECT * FROM Users as u WHERE u.email REGEXP "^[a-z0-9_]+@[a-z]+\.com$" ORDER BY u.user_id ASC; ```
0
0
['MySQL']
0
find-valid-emails
The most standard REGEXP
the-most-standard-regexp-by-zhuozhangjj-vgli
Code
ZhuoZhangjj
NORMAL
2025-03-06T08:15:13.083798+00:00
2025-03-06T08:15:13.083798+00:00
4
false
# Code ```postgresql [] -- Write your PostgreSQL query statement below SELECT user_id, email FROM Users WHERE email ~ '^[a-zA-Z0-9_]+@[a-zA-Z]+.com ORDER BY 1 ```
0
0
['PostgreSQL']
0
find-valid-emails
Something Interesting
something-interesting-by-shakhob-tr53
Code
Shakhob
NORMAL
2025-03-06T04:06:36.071383+00:00
2025-03-06T04:06:36.071383+00:00
6
false
# Code ```postgresql [] select user_id, email from users where email ~ '^\w+@\w+\.com' group by user_id, email ```
0
0
['PostgreSQL']
0
find-valid-emails
MySQL solution with REGEXP
mysql-solution-with-regexp-by-altz79-t9lg
IntuitionUse REGEXP for data filtering.ApproachWe can filter the 'email' column using REGEX expression, that will do the following:^: matches the beginning of t
altz79
NORMAL
2025-03-03T11:32:08.427338+00:00
2025-03-03T11:32:08.427338+00:00
4
false
# Intuition Use REGEXP for data filtering. # Approach We can filter the 'email' column using REGEX expression, that will do the following: ^: matches the beginning of text. [A-Za-z0-9_]+: matches one or more alphanumeric characters (uppercase or lowercase) or underscores. This will take all before the @ symbol. @: matches the @ symbol. [A-Za-z]+: matches one or more letter (uppercase or lowercase). Capture the domain name part. \\.com: matches the .com (the \ escapes the . to treat it as a literal dot, not a wildcard). $: matches the end of text. ORDER BY just sorting the values in required order. # Complexity - Time complexity: O(n log n) - because of the ORDER BY sorting. Without it - will improve to O(n). - Space complexity: O(n) - as we're selecting all the rows in the table with 'SELECT *'. # Code ```mysql [] # Write your MySQL query statement below SELECT * FROM Users WHERE email REGEXP '^[A-Za-z0-9_]+@[A-Za-z]+\\.com$' ORDER BY user_id; ```
0
0
['MySQL']
0
find-valid-emails
Easy to understand solution
easy-to-understand-solution-by-hendrilab-etvv
IntuitionApproachComplexity Time complexity: Space complexity: CodeORDER BY user_id ;
HendriLab
NORMAL
2025-03-03T06:54:54.013570+00:00
2025-03-03T06:54:54.013570+00:00
7
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below SELECT * FROM Users WHERE email REGEXP '^[\\w]+@[a-zA-Z]+\.com ``` ORDER BY user_id ; ```
0
0
['MySQL']
0
find-valid-emails
SUPER EASY EXPLAINED THE REGEXP FUNCTION || HAVE A LOOK TO MASTER REGEXP
super-easy-explained-the-regexp-function-63oe
IntuitionApproachComplexity Time complexity: Space complexity: CodeORDER BY user_id ASC; -- ^starts the String -- [a-zA-Z0-9_] matches the character before @ -
Aakrit_Bhandari05
NORMAL
2025-03-02T05:08:56.433467+00:00
2025-03-02T05:08:56.433467+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below SELECT user_id , email from Users where email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com ``` ORDER BY user_id ASC; -- ^starts the String -- [a-zA-Z0-9_] matches the character before @ -- @ checks for 1 @ -- [a-zA-Z] matches character after @ -- \\. escapes the . character -- .com matches the end -- $ End of String ```
0
0
['MySQL']
0
find-valid-emails
Mysql Solution
mysql-solution-by-abdulhey19-z3sn
IntuitionApproachComplexity Time complexity: Space complexity: CodeORDER BY user_id;
abdulhey19
NORMAL
2025-02-26T18:21:25.503767+00:00
2025-02-26T18:21:25.503767+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below SELECT * FROM users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com ``` ORDER BY user_id; ```
0
0
['MySQL']
0
find-valid-emails
MySQL REGEXP
mysql-regexp-by-9tiihc8xff-f0fg
Code
9tIIHC8XFF
NORMAL
2025-02-23T12:27:28.632896+00:00
2025-02-23T12:27:28.632896+00:00
4
false
# Code ```mysql [] # Write your MySQL query statement below SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9\\_]+\\@[a-zA-Z]+\\.com' ORDER BY user_id ```
0
0
['MySQL']
0
find-valid-emails
Easy MySQL
easy-mysql-by-orangeesoda-zgnz
Code
OrangeeSoda
NORMAL
2025-02-23T02:21:01.662175+00:00
2025-02-23T02:21:01.662175+00:00
7
false
# Code ```mysql [] # Write your MySQL query statement below select * from Users where regexp_like(email, '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com') order by user_id ```
0
0
['MySQL']
0
find-valid-emails
Simple solution using REGEXP.
simple-solution-using-regexp-by-khamdam-bdvu
Code
Khamdam
NORMAL
2025-02-22T20:30:25.586881+00:00
2025-02-22T20:31:58.302521+00:00
4
false
# Code ```mysql [] SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com$' ORDER BY user_id; ```
0
0
['MySQL']
0
find-valid-emails
Simple Regex Based Solution
simple-regex-based-solution-by-sj4u-pku9
Code
SJ4u
NORMAL
2025-02-22T10:06:40.637337+00:00
2025-02-22T10:06:40.637337+00:00
6
false
# Code ```postgresql [] -- Write your PostgreSQL query statement below select * from Users where email ~ '^([a-z]|[A-Z]|[0-9]|[_])+@([a-z]|[A-Z])+.com ``` ORDER BY user_id ASC; ```
0
0
['PostgreSQL']
0
find-valid-emails
simple regexp solution | postgresql
simple-regexp-solution-postgresql-by-tsu-q2aq
Code
tsukerin
NORMAL
2025-02-20T16:50:13.081825+00:00
2025-02-20T16:50:13.081825+00:00
9
false
# Code ```postgresql [] SELECT * FROM Users WHERE email ~* '^[a-zA-Z_0-9]+@[a-z]+\.com ```
0
0
['PostgreSQL']
0
find-valid-emails
MySQL - Regex
mysql-regex-by-sujansupraj-rcih
IntuitionApproachComplexity Time complexity: Space complexity: Code
sujansupraj
NORMAL
2025-02-19T16:05:47.061127+00:00
2025-02-19T16:05:47.061127+00:00
10
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] select * from users where email regexp '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com ``` ```
0
0
['MySQL']
0
find-valid-emails
MYSQL REGEXP Solution
mysql-regexp-solution-by-nursultankassym-tp6j
CodeORDER BYuser_id
nursultankassym
NORMAL
2025-02-19T13:44:31.473489+00:00
2025-02-19T13:44:31.473489+00:00
5
false
# Code ```mysql [] # Write your MySQL query statement below SELECT * FROM Users WHERE email REGEXP '^[A-Za-z0-9_]+@[A-Za-z]+\.com ``` ORDER BY user_id ```
0
0
['MySQL']
0
find-valid-emails
Simple and easy !
simple-and-easy-by-coder_pro_max28-35l0
IntuitionUsing Regular expressionsApproachSimple regex solution , using regex for pattern matchingComplexity Time complexity: Worst-case O(N × M) for filtering,
Coder_pro_max28
NORMAL
2025-02-19T10:56:37.357012+00:00
2025-02-19T10:56:37.357012+00:00
11
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Using Regular expressions # Approach <!-- Describe your approach to solving the problem. --> Simple regex solution , using regex for pattern matching # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> Worst-case O(N × M) for filtering, O(N log N) for sorting. If user_id is indexed, sorting is O(N). - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> Space complexity is O(N) in case sorting requires memory. # Code ```mysql [] # Write your MySQL query statement below SELECT * FROM Users WHERE email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com' ORDER BY user_id ```
0
0
['MySQL']
0
find-valid-emails
Readability guaranteed + no regex
readability-guaranteed-no-regex-by-kisha-07sx
Code
kishan3001
NORMAL
2025-02-18T17:32:29.962868+00:00
2025-02-18T17:32:29.962868+00:00
7
false
# Code ```pythondata [] import pandas as pd def find_valid_emails(users: pd.DataFrame) -> pd.DataFrame: def find_valid_email(email): cond_1 = email.count('@') == 1 cond_2 = email[-4:] == '.com' cond_3 = all([ char.isalnum() or char =='_' for char in email[:email.find('@')] ]) cond_4 = email[ (email.find('@')+1) : email.find('.com') ].isalpha() return cond_1 and cond_2 and cond_3 and cond_4 users['valid'] = users['email'].map(find_valid_email) return users[users['valid']][[ 'user_id', 'email']] ```
0
0
['Pandas']
0
find-valid-emails
Solution.
solution-by-guerinik-abderrahmane-2hj5
CodeORDER BY user_id;
Guerinik-Abderrahmane
NORMAL
2025-02-17T16:33:56.223394+00:00
2025-02-17T16:33:56.223394+00:00
9
false
# Code ```mysql [] # Write your MySQL query statement below SELECT user_id, email FROM users WHERE email REGEXP '^[a-zA-Z0-9]+@[a-zA-Z]+.com ``` ORDER BY user_id; ```
0
0
['MySQL']
0
find-valid-emails
Simple Solution Using REGEXP.
simple-solution-using-regexp-by-deep_ran-ssvw
IntuitionApproachComplexity Time complexity: Space complexity: Code
Deep_Rana
NORMAL
2025-02-17T06:58:36.682650+00:00
2025-02-17T06:58:36.682650+00:00
10
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below select * from Users where email regexp '^[a-zA-Z0-9_]+@[a-zA-Z]+.com ``` order by user_id; ```
0
0
['MySQL']
0
find-valid-emails
Easy Solution with Explanation
easy-solution-with-explanation-by-sharon-iaqv
IntuitionRetrieves all columns from the Users table with filtered rows based on a regular expression match.Approach ^ → Indicates the start position of the stri
sharonwang1
NORMAL
2025-02-13T23:49:28.547729+00:00
2025-02-13T23:49:28.547729+00:00
11
false
# Intuition Retrieves all columns from the Users table with filtered rows based on a regular expression match. # Approach - `^` → Indicates the start position of the string. - `[a-zA-Z0-9_]` → Matches any letter (uppercase or lowercase), digit (0-9), or underscore (_). - `+` → Ensures that at least one or more of the previous characters exist (i.e., the local part of the email must have at least one character). - `[a-zA-Z]+` → Matches one or more uppercase or lowercase letters (ensuring a valid domain name). - `\.com` → Matches a literal .com (escaped because . is a special character in regex). - `$` → Indicates the end position of the string. # Code ```mysql [] # Write your MySQL query statement below select * from Users where email regexp '^[a-zA-Z0-9_]+@[a-zA-Z]+\.com$' order by user_id ```
0
0
['MySQL']
0
find-valid-emails
Postgresql regex solution
postgresql-regex-solution-by-univega79-jj59
Code
Univega79
NORMAL
2025-02-12T01:01:46.703169+00:00
2025-02-12T01:01:46.703169+00:00
14
false
# Code ```postgresql [] select * from users where email ~ '^[a-zA-Z0-9]+@[a-zA-Z]+[.]com ``` ```
0
0
['PostgreSQL']
0
find-valid-emails
This will mostly work for the question
this-will-mostly-work-for-the-question-b-6lgx
IntuitionApproachComplexity Time complexity: Space complexity: CodeORDER BY user_id;
Pritam_das
NORMAL
2025-02-11T05:42:55.218687+00:00
2025-02-11T05:42:55.218687+00:00
17
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mysql [] # Write your MySQL query statement below SELECT user_id, email FROM Users WHERE -- Ensure exactly one "@" symbol email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com ``` ORDER BY user_id; ```
0
0
['MySQL']
0
find-valid-emails
Use LIKE - NOT LIKE - PATINDEX - CHARINDEX
use-like-not-like-patindex-charindex-by-wd16g
IntuitionApproachComplexity Time complexity: Space complexity: Code
exp_with_1K_SELECT_query
NORMAL
2025-02-10T16:15:46.591974+00:00
2025-02-10T16:15:46.591974+00:00
53
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```mssql [] /* Write your T-SQL query statement below */ SELECT user_id, email FROM Users WHERE email LIKE '[a-zA-Z0-9_]%@[a-zA-Z]%.com' AND email NOT LIKE '%@%@%' AND PATINDEX('%[^a-zA-Z0-9_]%', LEFT(email, CHARINDEX('@', email) - 1)) = 0 AND PATINDEX('%[^a-zA-Z]%', SUBSTRING(email, CHARINDEX('@', email) + 1, CHARINDEX('.com', email) - CHARINDEX('@', email) - 1)) = 0 ORDER BY user_id; ```
0
0
['MS SQL Server']
0
find-valid-emails
EXPLAINED SOLUTION USING SQL (MSSQL)
explained-solution-using-sql-mssql-by-ra-j4bd
IntuitionSo I feel tired to work on this small problem using SQL, since I want to find a solution that matches the full requirement.So to check if we have only
RachidBelouche
NORMAL
2025-02-10T10:59:12.803903+00:00
2025-02-10T10:59:12.803903+00:00
52
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> So I feel tired to work on this small problem using SQL, since I want to find a solution that matches the full requirement. So to check if we have only one @ symbol, we have to compare the length of email with the length of the replaced @ symbol with empty character, so the difference should be equal to 1, that means we have replaced one character found in the email. To check if it ends with .com we can use like %.com To check for alphanumeric and underscores, we have to use PATINDEX the pattern from the substring if it's equal to 0, so we have to use the negative of the pattern (not the pattern). Then we have to order by user_id. # Approach <!-- Describe your approach to solving the problem. --> 1. Select from the user. ``` SELECT user_id, email FROM Users ``` 2. It contains exactly one @ symbol. ``` LEN(email) - LEN(REPLACE(email, '@', '')) = 1 -- It contains exactly one @ symbol. ``` 3. The part before the @ symbol contains only alphanumeric characters and underscores. ``` email like '%.com' -- It ends with .com. ``` 4. The part before the @ symbol contains only alphanumeric characters and underscores. ``` PATINDEX('%[^a-z0-9_]%', SUBSTRING(email, 1, CHARINDEX('@', email) - 1)) <= 0 -- The part before the @ symbol contains only alphanumeric characters and underscores. ``` 5. The part after the @ symbol and before .com contains a domain name that contains only letters. ``` PATINDEX('[^a-z0-9]',SUBSTRING(email, CHARINDEX('@', email) + 1, CHARINDEX('.com', email) - CHARINDEX('@', email) - 1)) <= 0 -- The part after the @ symbol and before .com contains a domain name that contains only letters. ``` 6. Return the result table ordered by user_id in ascending order. ``` ORDER BY user_id; -- Return the result table ordered by user_id in ascending order. ``` # Code ```mssql [] /* Write your T-SQL query statement below */ SELECT user_id, email FROM Users WHERE LEN(email) - LEN(REPLACE(email, '@', '')) = 1 -- It contains exactly one @ symbol. AND email like '%.com' -- It ends with .com. AND PATINDEX('%[^a-z0-9_]%', SUBSTRING(email, 1, CHARINDEX('@', email) - 1)) <= 0 -- The part before the @ symbol contains only alphanumeric characters and underscores. AND PATINDEX('[^a-z0-9]',SUBSTRING(email, CHARINDEX('@', email) + 1, CHARINDEX('.com', email) - CHARINDEX('@', email) - 1)) <= 0 -- The part after the @ symbol and before .com contains a domain name that contains only letters. ORDER BY user_id; -- Return the result table ordered by user_id in ascending order. ```
0
0
['Database', 'MS SQL Server']
0
find-valid-emails
[MySQL] Simple solution
mysql-simple-solution-by-samuel3shin-16y1
Code
Samuel3Shin
NORMAL
2025-02-09T01:00:38.362146+00:00
2025-02-09T01:00:38.362146+00:00
22
false
# Code ```mysql [] # Write your MySQL query statement below SELECT user_id, email FROM Users WHERE email LIKE '%@%.com' ```
0
0
['MySQL']
0
find-valid-emails
[MySQL] Plain SELECT, plus RegExp
mysql-plain-select-plus-regexp-by-ajna2-evq1
Really, not much to discuss; we will just need to get REGEXP matches so that: the first part matches alphanumerical characters and _, which we can get by groupi
Ajna2
NORMAL
2025-02-09T00:35:21.699314+00:00
2025-02-09T00:35:21.699314+00:00
33
false
Really, not much to discuss; we will just need to get `REGEXP` matches so that: * the first part matches alphanumerical characters and `_`, which we can get by grouping with `[a-z0-9_]` (`\w` would work too, but I preferred a more explicit form) and a `+` (meaning one or more matches); * then we have a `@` * next comes the domain, made of only letters (ie: `[a-z]`), again, one or more of them, so another `+`; * finally we have an escaped `.` and then `com`. # Code ```mysql [] # Write your MySQL query statement below SELECT user_id, email FROM Users WHERE (email REGEXP '[a-z0-9_]+@[a-z]+\.com'); ```
0
0
['MySQL']
2