Maximum Substrings With Distinct Start

You are given a string s consisting of lowercase English letters.

You need to partition s into one or more contiguous substrings. Return the maximum number of substrings you can split s into, such that every single substring begins with a distinct character (i.e., no two substrings share the same starting character).

Example 1:

Input: s = "abac"

Output: 3

Explanation:

We can split the string into "a", "b", and "ac". The starting letters are 'a', 'b', and 'c', which are all perfectly distinct.

Example 2:

Input: s = "zzzz"

Output: 1

Explanation:

Since all letters are 'z', any split will result in multiple chunks starting with 'z'. Thus, we can only have 1 single chunk: "zzzz".

Now Your Turn!

Pick the correct output for the given input

Input: s = "bcbac"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s consists entirely of lowercase English letters.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int maximumSubstrings(string s) {
}
};
Test Case

Input:

S