Skip to content
Discussion options

You must be logged in to vote

We need to filter and sort coupon data based on specific validation rules. Let me break down the requirements and implement a solution.

Approach:

I'll follow these steps:

  1. Filter out invalid coupons using the three conditions
  2. Map business lines to a priority order for sorting
  3. Sort valid coupons first by business line priority, then by code
  4. Return just the codes in the correct order

Let's implement this solution in PHP: 3606. Coupon Code Validator

<?php
/**
 * @param String[] $code
 * @param String[] $businessLine
 * @param Boolean[] $isActive
 * @return String[]
 */
function validateCoupons($code, $businessLine, $isActive) {
    $priority = ['electronics' => 0, 'grocery' => 1, 'pharmacy'

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Dec 13, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 13, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants