|
| 1 | +<h2><a href="https://leetcode.com/problems/coupon-code-validator">3934. Coupon Code Validator</a></h2><h3>Easy</h3><hr><p>You are given three arrays of length <code>n</code> that describe the properties of <code>n</code> coupons: <code>code</code>, <code>businessLine</code>, and <code>isActive</code>. The <code>i<sup>th</sup> </code>coupon has:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>code[i]</code>: a <strong>string</strong> representing the coupon identifier.</li> |
| 5 | + <li><code>businessLine[i]</code>: a <strong>string</strong> denoting the business category of the coupon.</li> |
| 6 | + <li><code>isActive[i]</code>: a <strong>boolean</strong> indicating whether the coupon is currently active.</li> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p>A coupon is considered <strong>valid</strong> if all of the following conditions hold:</p> |
| 10 | + |
| 11 | +<ol> |
| 12 | + <li><code>code[i]</code> is non-empty and consists only of alphanumeric characters (a-z, A-Z, 0-9) and underscores (<code>_</code>).</li> |
| 13 | + <li><code>businessLine[i]</code> is one of the following four categories: <code>"electronics"</code>, <code>"grocery"</code>, <code>"pharmacy"</code>, <code>"restaurant"</code>.</li> |
| 14 | + <li><code>isActive[i]</code> is <strong>true</strong>.</li> |
| 15 | +</ol> |
| 16 | + |
| 17 | +<p>Return an array of the <strong>codes</strong> of all valid coupons, <strong>sorted</strong> first by their <strong>businessLine</strong> in the order: <code>"electronics"</code>, <code>"grocery"</code>, <code>"pharmacy", "restaurant"</code>, and then by <strong>code</strong> in lexicographical (ascending) order within each category.</p> |
| 18 | + |
| 19 | +<p> </p> |
| 20 | +<p><strong class="example">Example 1:</strong></p> |
| 21 | + |
| 22 | +<div class="example-block"> |
| 23 | +<p><strong>Input:</strong> <span class="example-io">code = ["SAVE20","","PHARMA5","SAVE@20"], businessLine = ["restaurant","grocery","pharmacy","restaurant"], isActive = [true,true,true,true]</span></p> |
| 24 | + |
| 25 | +<p><strong>Output:</strong> <span class="example-io">["PHARMA5","SAVE20"]</span></p> |
| 26 | + |
| 27 | +<p><strong>Explanation:</strong></p> |
| 28 | + |
| 29 | +<ul> |
| 30 | + <li>First coupon is valid.</li> |
| 31 | + <li>Second coupon has empty code (invalid).</li> |
| 32 | + <li>Third coupon is valid.</li> |
| 33 | + <li>Fourth coupon has special character <code>@</code> (invalid).</li> |
| 34 | +</ul> |
| 35 | +</div> |
| 36 | + |
| 37 | +<p><strong class="example">Example 2:</strong></p> |
| 38 | + |
| 39 | +<div class="example-block"> |
| 40 | +<p><strong>Input:</strong> <span class="example-io">code = ["GROCERY15","ELECTRONICS_50","DISCOUNT10"], businessLine = ["grocery","electronics","invalid"], isActive = [false,true,true]</span></p> |
| 41 | + |
| 42 | +<p><strong>Output:</strong> <span class="example-io">["ELECTRONICS_50"]</span></p> |
| 43 | + |
| 44 | +<p><strong>Explanation:</strong></p> |
| 45 | + |
| 46 | +<ul> |
| 47 | + <li>First coupon is inactive (invalid).</li> |
| 48 | + <li>Second coupon is valid.</li> |
| 49 | + <li>Third coupon has invalid business line (invalid).</li> |
| 50 | +</ul> |
| 51 | +</div> |
| 52 | + |
| 53 | +<p> </p> |
| 54 | +<p><strong>Constraints:</strong></p> |
| 55 | + |
| 56 | +<ul> |
| 57 | + <li><code>n == code.length == businessLine.length == isActive.length</code></li> |
| 58 | + <li><code>1 <= n <= 100</code></li> |
| 59 | + <li><code>0 <= code[i].length, businessLine[i].length <= 100</code></li> |
| 60 | + <li><code>code[i]</code> and <code>businessLine[i]</code> consist of printable ASCII characters.</li> |
| 61 | + <li><code>isActive[i]</code> is either <code>true</code> or <code>false</code>.</li> |
| 62 | +</ul> |
0 commit comments