Skip to content

Practice Coupon Code Validator

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

Easy#3606
LeetCode Problem

Coupon Code Validator

Problem Statement

Coupon i has identifier code[i], category businessLine[i], and activation flag isActive[i]. It is valid only when active, its nonempty identifier contains only English letters, digits, and underscores, and its category is electronics, grocery, pharmacy, or restaurant. Return valid identifiers ordered by those four categories in that order, then lexicographically within each category.

Source: Coupon Code Validator on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
code = ["SAVE20","","PHARMA5","SAVE@20"], businessLine = ["restaurant","grocery","pharmacy","restaurant"], isActive = [true,true,true,true]
Output
["PHARMA5","SAVE20"]

# Example 2

Input
code = ["GROCERY15","ELECTRONICS_50","DISCOUNT10"], businessLine = ["grocery","electronics","invalid"], isActive = [false,true,true]
Output
["ELECTRONICS_50"]

Constraints

n == code.length == businessLine.length == isActive.length
1 <= n <= 100
0 <= code[i].length, businessLine[i].length <= 100
code[i] and businessLine[i] consist of printable ASCII characters.
isActive[i] is either true or false.

Related LeetCode Problems

Practice more problems similar to Coupon Code Validator.

Review your practice with PhantomCodeAI

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