3. Longest Substring Without Repeating Characters | Sliding Window Explained in C++ |

Опубликовано: 29 Июль 2026
на канале: Atul Singh
7
0

In this video, I solve LeetCode 3: Longest Substring Without Repeating Characters using the Sliding Window approach in C++.

✅ Problem Explanation
✅ Optimized Approach
✅ Dry Run
✅ Time & Space Complexity
✅ Clean C++ STL-Based Code

Approach:
We use two pointers `left` and `right` with a set to maintain the current substring without duplicate characters.

If a character is not present in the set, we add it and expand the window.
If a duplicate character is found, we remove characters from the left side until the duplicate is removed.

Algorithm:

1. Initialize `left = 0`, `right = 0`
2. Create an unordered_set to store characters
3. Move `right` pointer through the string
4. If character is not present, insert it and update maximum length
5. If duplicate is found, remove characters from left side
6. Continue until the full string is processed

Time Complexity: O(N)
Space Complexity: O(N)

🔗 GitHub:
https://github.com/atulXdev

🔗 LeetCode Profile:
https://leetcode.com/u/atul_singh_cg/

🔗 LinkedIn:
  / atul-singh-987b0b394  

#leetcode #dsa #cpp #longestsubstringwithoutrepeatingcharacters #slidingwindow #strings #codinginterview #striverdsa #leetcode3 #datastructures #algorithms