mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 06:51:41 +08:00
63 lines
3.2 KiB
HTML
63 lines
3.2 KiB
HTML
<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>
|
|
|
|
<ul>
|
|
<li><code>code[i]</code>: a <strong>string</strong> representing the coupon identifier.</li>
|
|
<li><code>businessLine[i]</code>: a <strong>string</strong> denoting the business category of the coupon.</li>
|
|
<li><code>isActive[i]</code>: a <strong>boolean</strong> indicating whether the coupon is currently active.</li>
|
|
</ul>
|
|
|
|
<p>A coupon is considered <strong>valid</strong> if all of the following conditions hold:</p>
|
|
|
|
<ol>
|
|
<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>
|
|
<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>
|
|
<li><code>isActive[i]</code> is <strong>true</strong>.</li>
|
|
</ol>
|
|
|
|
<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>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<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>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">["PHARMA5","SAVE20"]</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<ul>
|
|
<li>First coupon is valid.</li>
|
|
<li>Second coupon has empty code (invalid).</li>
|
|
<li>Third coupon is valid.</li>
|
|
<li>Fourth coupon has special character <code>@</code> (invalid).</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">code = ["GROCERY15","ELECTRONICS_50","DISCOUNT10"], businessLine = ["grocery","electronics","invalid"], isActive = [false,true,true]</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">["ELECTRONICS_50"]</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<ul>
|
|
<li>First coupon is inactive (invalid).</li>
|
|
<li>Second coupon is valid.</li>
|
|
<li>Third coupon has invalid business line (invalid).</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>n == code.length == businessLine.length == isActive.length</code></li>
|
|
<li><code>1 <= n <= 100</code></li>
|
|
<li><code>0 <= code[i].length, businessLine[i].length <= 100</code></li>
|
|
<li><code>code[i]</code> and <code>businessLine[i]</code> consist of printable ASCII characters.</li>
|
|
<li><code>isActive[i]</code> is either <code>true</code> or <code>false</code>.</li>
|
|
</ul>
|