|
| 1 | +<p>You are given a string <code>s</code> consisting only of digits. A <strong>valid pair</strong> is defined as two <strong>adjacent</strong> digits in <code>s</code> such that:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>The first digit is <strong>not equal</strong> to the second.</li> |
| 5 | + <li>Each digit in the pair appears in <code>s</code> <strong>exactly</strong> as many times as its numeric value.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>Return the first <strong>valid pair</strong> found in the string <code>s</code> when traversing from left to right. If no valid pair exists, return an empty string.</p> |
| 9 | + |
| 10 | +<p> </p> |
| 11 | +<p><strong class="example">Example 1:</strong></p> |
| 12 | + |
| 13 | +<div class="example-block"> |
| 14 | +<p><strong>Input:</strong> <span class="example-io">s = "2523533"</span></p> |
| 15 | + |
| 16 | +<p><strong>Output:</strong> <span class="example-io">"23"</span></p> |
| 17 | + |
| 18 | +<p><strong>Explanation:</strong></p> |
| 19 | + |
| 20 | +<p>Digit <code>'2'</code> appears 2 times and digit <code>'3'</code> appears 3 times. Each digit in the pair <code>"23"</code> appears in <code>s</code> exactly as many times as its numeric value. Hence, the output is <code>"23"</code>.</p> |
| 21 | +</div> |
| 22 | + |
| 23 | +<p><strong class="example">Example 2:</strong></p> |
| 24 | + |
| 25 | +<div class="example-block"> |
| 26 | +<p><strong>Input:</strong> <span class="example-io">s = "221"</span></p> |
| 27 | + |
| 28 | +<p><strong>Output:</strong> <span class="example-io">"21"</span></p> |
| 29 | + |
| 30 | +<p><strong>Explanation:</strong></p> |
| 31 | + |
| 32 | +<p>Digit <code>'2'</code> appears 2 times and digit <code>'1'</code> appears 1 time. Hence, the output is <code>"21"</code>.</p> |
| 33 | +</div> |
| 34 | + |
| 35 | +<p><strong class="example">Example 3:</strong></p> |
| 36 | + |
| 37 | +<div class="example-block"> |
| 38 | +<p><strong>Input:</strong> <span class="example-io">s = "22"</span></p> |
| 39 | + |
| 40 | +<p><strong>Output:</strong> <span class="example-io">""</span></p> |
| 41 | + |
| 42 | +<p><strong>Explanation:</strong></p> |
| 43 | + |
| 44 | +<p>There are no valid adjacent pairs.</p> |
| 45 | +</div> |
| 46 | + |
| 47 | +<p> </p> |
| 48 | +<p><strong>Constraints:</strong></p> |
| 49 | + |
| 50 | +<ul> |
| 51 | + <li><code>2 <= s.length <= 100</code></li> |
| 52 | + <li><code>s</code> only consists of digits from <code>'1'</code> to <code>'9'</code>.</li> |
| 53 | +</ul> |
0 commit comments