Leetcode Problem 2743. Count Substrings Without Repeating Character

2743. Count Substrings Without Repeating Character

Leetcode Solutions

Sliding Window Approach

  1. Initialize a result variable res to 0 to store the count of special substrings.
  2. Create a dictionary d to keep track of the last seen index of each character.
  3. Initialize a variable l to 0 to represent the start of the current window.
  4. Iterate through the string using a variable i to represent the end of the current window.
  5. For each character c at index i, check if c is in the dictionary d and if the last seen index is within the current window.
  6. If so, update l to be one more than the last seen index of c.
  7. Update the last seen index of c in the dictionary d.
  8. Add the length of the current window (i - l + 1) to res.
  9. Return res as the final count of special substrings.
UML Thumbnail

Brute Force Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...