Find Products with Three Consecutive Digits - Problem
You are given a table Products that contains product information. Your task is to find all products whose names contain exactly three consecutive digits.
Key Requirements:
- The sequence must be exactly three digits in a row
- Products may have multiple such sequences, but each qualifying sequence must be exactly 3 digits
- Return results ordered by
product_idin ascending order
Example: 'ABC123XYZ' contains '123' (3 consecutive digits), while 'Product56789' contains '56789' (5 consecutive digits, so it doesn't qualify).
Table Schema
Products
| Column Name | Type | Description |
|---|---|---|
product_id
PK
|
int | Unique identifier for each product |
name
|
varchar | Product name that may contain digits and letters |
Primary Key: product_id
Note: Each row represents a unique product with its ID and name
Input & Output
Example 1 — Mixed Product Names
Input Table:
| product_id | name |
|---|---|
| 1 | ABC123XYZ |
| 2 | A12B34C |
| 3 | Product56789 |
| 4 | NoDigitsHere |
| 5 | 789Product |
| 6 | Item003Description |
| 7 | Product12X34 |
Output:
| product_id | name |
|---|---|
| 1 | ABC123XYZ |
| 5 | 789Product |
| 6 | Item003Description |
💡 Note:
Pattern Analysis:
ABC123XYZcontains exactly 3 consecutive digits:123A12B34Chas digits but not 3 consecutive onesProduct56789has 5 consecutive digits (too many)NoDigitsHerehas no digits789Productstarts with exactly 3 consecutive digitsItem003Descriptioncontains exactly 3 consecutive digits:003
Example 2 — Edge Cases
Input Table:
| product_id | name |
|---|---|
| 1 | 12 |
| 2 | 1234 |
| 3 | A123B456C |
| 4 | 000 |
Output:
| product_id | name |
|---|---|
| 3 | A123B456C |
| 4 | 000 |
💡 Note:
Edge Case Analysis:
12- only 2 digits (too few)1234- 4 consecutive digits (too many)A123B456C- contains two separate groups of exactly 3 digits each000- exactly 3 consecutive digits (leading zeros count)
Constraints
-
1 ≤ product_id ≤ 1000 -
namecontains only alphanumeric characters - Product names can be up to 50 characters long
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code