Skip to content

Practice Find Products with Valid Serial Numbers

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

Easy#3465
LeetCode Problem

Find Products with Valid Serial Numbers

Problem Statement

Table products has product_id INT, product_name VARCHAR, and description VARCHAR. Return products whose description contains uppercase SN followed by four digits, a hyphen, and exactly four more digits. The match can occur inside the description, but must not accept a prefix of a longer trailing digit run. Return all three columns ordered by product_id ascending. Practice approach: Use a case-sensitive pattern with exact digit counts and a nondigit-or-end condition after the final group. A bare substring pattern incorrectly accepts a serial with five trailing digits. Test lowercase sn, extra digits on either side of the hyphen, and a valid match inside surrounding prose.

Source: Find Products with Valid Serial Numbers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
{
  "products": [
    {
      "product_id": 1,
      "product_name": "A",
      "description": "Box SN2468-1357 ready"
    },
    {
      "product_id": 2,
      "product_name": "B",
      "description": "Box SN2468-13579 ready"
    },
    {
      "product_id": 3,
      "product_name": "C",
      "description": "sn2468-1357"
    },
    {
      "product_id": 4,
      "product_name": "D",
      "description": "SN24689-1357"
    },
    {
      "product_id": 5,
      "product_name": "E",
      "description": "Code SN1111-2222."
    }
  ]
}
Output
[
  {
    "product_id": 1,
    "product_name": "A",
    "description": "Box SN2468-1357 ready"
  },
  {
    "product_id": 5,
    "product_name": "E",
    "description": "Code SN1111-2222."
  }
]
Explanation

The second product has five trailing digits, the third has a lowercase prefix, and the fourth has five digits before its hyphen.

Constraints

product_id is unique.
SN is case-sensitive; both digit groups have exactly four digits.

Related LeetCode Problems

Practice more problems similar to Find Products with Valid Serial Numbers.

Review your practice with PhantomCodeAI

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