PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

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.

  • hard
  • NVIDIA
  • Coding & Algorithms
  • Software Engineer

Count Substrings with No Repeated Characters

Company: NVIDIA

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

# Count Substrings with No Repeated Characters Given a lowercase English string `s`, return the number of nonempty contiguous substrings whose characters are all distinct. Substrings with different start or end positions are counted separately even if their text is the same. Implement: ```python def solve(s: str) -> int: ... ``` ## Constraints - `1 <= len(s) <= 100_000` - `s` contains only `a` through `z`. ## Examples ```text s = "abca" -> 9 s = "aaa" -> 3 ``` For `"abca"`, the valid substrings are the four single characters, `"ab"`, `"bc"`, `"ca"`, `"abc"`, and `"bca"`.

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.

Implement solve(s). Return the number of non-empty contiguous substrings of the lowercase string whose characters are all distinct. Different index ranges count separately even when their text is equal.

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

  1. Maintain the left edge of the longest distinct-character window ending at each position.
  2. That window length equals the number of valid substrings ending at the current position.
Last updated: Jul 18, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Determine Whether One Point Can Reach Another - NVIDIA (hard)
  • Compute the Final Robot Score - NVIDIA (easy)
  • Merge Overlapping Time Intervals - NVIDIA (medium)
  • Return all file paths via DFS - NVIDIA (easy)