[LeetCode] Maximum Substrings With Distinct Start

3760. Maximum Substrings With Distinct Start

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

Return an integer denoting the maximum number of substrings you can split s into such that each substring starts with a distinct character (i.e., no two substrings start with the same character).

1
2
3
4
5
6
7
8
class Solution {
public:
int maxDistinct(string s) {
int bit = 0;
for(auto& ch : s) bit |= (1<<(ch-'a'));
return __builtin_popcount(bit);
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/maximum-substrings-with-distinct-start/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.