|
| 1 | +<h2><a href="https://leetcode.com/problems/lexicographically-minimum-string-after-removing-stars/?envType=daily-question&envId=2025-06-07">3170. Lexicographically Minimum String After Removing Stars</a></h2><h3>Medium</h3><hr><p>You are given a string <code>s</code>. It may contain any number of <code>'*'</code> characters. Your task is to remove all <code>'*'</code> characters.</p> |
| 2 | + |
| 3 | +<p>While there is a <code>'*'</code>, do the following operation:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>Delete the leftmost <code>'*'</code> and the <strong>smallest</strong> non-<code>'*'</code> character to its <em>left</em>. If there are several smallest characters, you can delete any of them.</li> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p>Return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> resulting string after removing all <code>'*'</code> characters.</p> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<div class="example-block"> |
| 15 | +<p><strong>Input:</strong> <span class="example-io">s = "aaba*"</span></p> |
| 16 | + |
| 17 | +<p><strong>Output:</strong> <span class="example-io">"aab"</span></p> |
| 18 | + |
| 19 | +<p><strong>Explanation:</strong></p> |
| 20 | + |
| 21 | +<p>We should delete one of the <code>'a'</code> characters with <code>'*'</code>. If we choose <code>s[3]</code>, <code>s</code> becomes the lexicographically smallest.</p> |
| 22 | +</div> |
| 23 | + |
| 24 | +<p><strong class="example">Example 2:</strong></p> |
| 25 | + |
| 26 | +<div class="example-block"> |
| 27 | +<p><strong>Input:</strong> <span class="example-io">s = "abc"</span></p> |
| 28 | + |
| 29 | +<p><strong>Output:</strong> <span class="example-io">"abc"</span></p> |
| 30 | + |
| 31 | +<p><strong>Explanation:</strong></p> |
| 32 | + |
| 33 | +<p>There is no <code>'*'</code> in the string.<!-- notionvc: ff07e34f-b1d6-41fb-9f83-5d0ba3c1ecde --></p> |
| 34 | +</div> |
| 35 | + |
| 36 | +<p> </p> |
| 37 | +<p><strong>Constraints:</strong></p> |
| 38 | + |
| 39 | +<ul> |
| 40 | + <li><code>1 <= s.length <= 10<sup>5</sup></code></li> |
| 41 | + <li><code>s</code> consists only of lowercase English letters and <code>'*'</code>.</li> |
| 42 | + <li>The input is generated such that it is possible to delete all <code>'*'</code> characters.</li> |
| 43 | +</ul> |
0 commit comments