Count Substrings with No Repeated Characters
Company: NVIDIA
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: Count all nonempty contiguous substrings of a lowercase string that contain no repeated character. The input may contain 100,000 characters, and equal substring text still counts separately when it comes from different positions.
Constraints
- 1 <= len(s) <= 100,000
- s contains only a through z.
Examples
Input: ('a',)
Expected Output: 1
Explanation: Exercises sliding-window movement and positional counting.
Input: ('aaa',)
Expected Output: 3
Explanation: Exercises sliding-window movement and positional counting.
Hints
- Maintain the left edge of the longest distinct-character window ending at each position.
- That window length equals the number of valid substrings ending at the current position.