LeetCode Entry

3606. Coupon Code Validator

13.12.2025 easy 2025 kotlin rust

Filter a,b,c accroding to rules

3606. Coupon Code Validator easy blog post substack youtube

fd4f17a4-698f-410e-9dd9-1d3d56a1caf3 (1).webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1203

Problem TLDR

Filter a,b,c accroding to rules #easy

Intuition

Just read the rules.

Approach

  • some rules can be hacked around
  • the regex in koglin faster than in rust

Complexity

  • Time complexity: \(O(nlog(n))\)

  • Space complexity: \(O(n)\)

Code

// 57ms
    fun validateCoupons(c: Array<String>, b: Array<String>, a: BooleanArray) =
    c.indices.filter { a[it] && Regex("\\w+") matches c[it] && b[it][0] in "egpr" }
    .sortedBy { b[it][0] + c[it] }.map { c[it] }
// 0ms
    pub fn validate_coupons(c: Vec<String>, b: Vec<String>, a: Vec<bool>) -> Vec<String> {
        b.iter().map(|b|b.as_bytes()[0]).zip(c).zip(a).filter(|((b,c),a)|
            *a && b"egrp".contains(b) && c != "" && c.chars().all(|c|c.is_alphanumeric() || c == '_'))
        .sorted().map(|((_,c),_)|c).collect()
    }