3606. Coupon Code Validator Easy
1/**
2 * [3606] Coupon Code Validator
3 *
4 * You are given three arrays of length n that describe the properties of n coupons: code, businessLine, and isActive. The i^th coupon has:
5 *
6 * code[i]: a string representing the coupon identifier.
7 * businessLine[i]: a string denoting the business category of the coupon.
8 * isActive[i]: a boolean indicating whether the coupon is currently active.
9 *
10 * A coupon is considered valid if all of the following conditions hold:
11 * <ol>
12 * code[i] is non-empty and consists only of alphanumeric characters (a-z, A-Z, 0-9) and underscores (_).
13 * businessLine[i] is one of the following four categories: "electronics", "grocery", "pharmacy", "restaurant".
14 * isActive[i] is true.
15 * </ol>
16 * Return an array of the codes of all valid coupons, sorted first by their businessLine in the order: "electronics", "grocery", "pharmacy", "restaurant", and then by code in lexicographical (ascending) order within each category.
17 *
18 * <strong class="example">Example 1:
19 * <div class="example-block">
20 * Input: <span class="example-io">code = ["SAVE20","","PHARMA5","SAVE@20"], businessLine = ["restaurant","grocery","pharmacy","restaurant"], isActive = [true,true,true,true]</span>
21 * Output: <span class="example-io">["PHARMA5","SAVE20"]</span>
22 * Explanation:
23 *
24 * First coupon is valid.
25 * Second coupon has empty code (invalid).
26 * Third coupon is valid.
27 * Fourth coupon has special character @ (invalid).
28 * </div>
29 * <strong class="example">Example 2:
30 * <div class="example-block">
31 * Input: <span class="example-io">code = ["GROCERY15","ELECTRONICS_50","DISCOUNT10"], businessLine = ["grocery","electronics","invalid"], isActive = [false,true,true]</span>
32 * Output: <span class="example-io">["ELECTRONICS_50"]</span>
33 * Explanation:
34 *
35 * First coupon is inactive (invalid).
36 * Second coupon is valid.
37 * Third coupon has invalid business line (invalid).
38 * </div>
39 *
40 * Constraints:
41 *
42 * n == code.length == businessLine.length == isActive.length
43 * 1 <= n <= 100
44 * 0 <= code[i].length, businessLine[i].length <= 100
45 * code[i] and businessLine[i] consist of printable ASCII characters.
46 * isActive[i] is either true or false.
47 *
48 */
49pub struct Solution {}
50
51// problem: https://leetcode.com/problems/coupon-code-validator/
52// discuss: https://leetcode.com/problems/coupon-code-validator/discuss/?currentPage=1&orderBy=most_votes&query=
53
54// submission codes start here
55
56impl Solution {
57 pub fn validate_coupons(code: Vec<String>, business_line: Vec<String>, is_active: Vec<bool>) -> Vec<String> {
58 vec![]
59 }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_3606() {
70 }
71}
72Back
© 2026 bowen.ge All Rights Reserved.