Skip to main content
Back to problems
#3760
Medium Algorithms

Maximum substrings with distinct start

Hash Table String
91.3% acceptance
Feb 25, 2026
67
16
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).

Solution

Rust
Time O(n)
Space O(n)
LeetCode
solution.rs
impl Solution {
  pub fn max_distinct(s: String) -> i32 {
    let mut seen = [false; 26];
    for b in s.bytes() { seen[(b - b'a') as usize] = true; }
    seen.iter().filter(|&&x| x).count() as i32
  }
}