|
| 1 | +<h2><a href="https://leetcode.com/problems/maximum-substrings-with-distinct-start">Maximum Substrings With Distinct Start</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><p>You are given a string <code>s</code> consisting of lowercase English letters.</p> |
| 2 | + |
| 3 | +<p>Return an integer denoting the <strong>maximum</strong> number of <span data-keyword="substring-nonempty">substrings</span> you can split <code>s</code> into such that each <strong>substring</strong> starts with a <strong>distinct</strong> character (i.e., no two substrings start with the same character).</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<div class="example-block"> |
| 9 | +<p><strong>Input:</strong> <span class="example-io">s = "abab"</span></p> |
| 10 | + |
| 11 | +<p><strong>Output:</strong> <span class="example-io">2</span></p> |
| 12 | + |
| 13 | +<p><strong>Explanation:</strong></p> |
| 14 | + |
| 15 | +<ul> |
| 16 | + <li>Split <code>"abab"</code> into <code>"a"</code> and <code>"bab"</code>.</li> |
| 17 | + <li>Each substring starts with a distinct character i.e <code>'a'</code> and <code>'b'</code>. Thus, the answer is 2.</li> |
| 18 | +</ul> |
| 19 | +</div> |
| 20 | + |
| 21 | +<p><strong class="example">Example 2:</strong></p> |
| 22 | + |
| 23 | +<div class="example-block"> |
| 24 | +<p><strong>Input:</strong> <span class="example-io">s = "abcd"</span></p> |
| 25 | + |
| 26 | +<p><strong>Output:</strong> <span class="example-io">4</span></p> |
| 27 | + |
| 28 | +<p><strong>Explanation:</strong></p> |
| 29 | + |
| 30 | +<ul> |
| 31 | + <li>Split <code>"abcd"</code> into <code>"a"</code>, <code>"b"</code>, <code>"c"</code>, and <code>"d"</code>.</li> |
| 32 | + <li>Each substring starts with a distinct character. Thus, the answer is 4.</li> |
| 33 | +</ul> |
| 34 | +</div> |
| 35 | + |
| 36 | +<p><strong class="example">Example 3:</strong></p> |
| 37 | + |
| 38 | +<div class="example-block"> |
| 39 | +<p><strong>Input:</strong> <span class="example-io">s = "aaaa"</span></p> |
| 40 | + |
| 41 | +<p><strong>Output:</strong> <span class="example-io">1</span></p> |
| 42 | + |
| 43 | +<p><strong>Explanation:</strong></p> |
| 44 | + |
| 45 | +<ul> |
| 46 | + <li>All characters in <code>"aaaa"</code> are <code>'a'</code>.</li> |
| 47 | + <li>Only one substring can start with <code>'a'</code>. Thus, the answer is 1.</li> |
| 48 | +</ul> |
| 49 | +</div> |
| 50 | + |
| 51 | +<p> </p> |
| 52 | +<p><strong>Constraints:</strong></p> |
| 53 | + |
| 54 | +<ul> |
| 55 | + <li><code>1 <= s.length <= 10<sup>5</sup></code></li> |
| 56 | + <li><code>s</code> consists of lowercase English letters.</li> |
| 57 | +</ul> |
0 commit comments