Skip to content

Commit 22b4f3b

Browse files
docs(revision): add algorithm descriptions for Day 02 string problems
1 parent 7f1c280 commit 22b4f3b

2 files changed

Lines changed: 27 additions & 30 deletions

File tree

CPP/revision/25-revision-questions/day-02-strings/01_longest_substring_without_repeating_characters.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
// 01_longest_substring_without_repeating_characters.cpp
2-
// Problem: Longest Substring Without Repeating Characters
3-
// LeetCode: https://leetcode.com/problems/longest-substring-without-repeating-characters/
4-
// Author: DeveloperViraj (curated DSA set for Hacktoberfest 2025)
5-
// Compile: g++ -std=c++17 01_longest_substring_without_repeating_characters.cpp -o 01_longest_substring
6-
// Run: ./01_longest_substring
72
//
8-
// Summary:
9-
// Given a string, find the length of the longest substring without repeating characters.
3+
// 🔍 Algorithm: Longest Substring Without Repeating Characters
4+
// Description:
5+
// Finds the length of the longest substring in a given string
6+
// that contains no repeating characters.
7+
// Uses the Sliding Window technique with a hash map to track
8+
// character indices and adjust window boundaries efficiently.
109
//
11-
// Approach (sliding window + last-seen index):
12-
// Use two indices (windowStart and windowEnd) and a map of last-seen indices for characters.
13-
// Expand the windowEnd and if the current character was seen inside the current window,
14-
// move windowStart to lastSeenIndex + 1. Update the maximum window length as you go.
10+
// Use Case:
11+
// Commonly used to analyze substring patterns or find unique
12+
// character sequences in data streams.
1513
//
16-
// Time Complexity: O(n) where n = length of string (each char visited at most twice).
17-
// Space Complexity: O(min(n, charset)) for the hash map of last seen indices.
18-
14+
// Time Complexity: O(n) — each character visited once.
15+
// Space Complexity: O(1) — constant size (at most 256 chars).
16+
//
17+
// LeetCode: https://leetcode.com/problems/longest-substring-without-repeating-characters/
1918
#include <iostream>
2019
#include <string>
2120
#include <unordered_map>

CPP/revision/25-revision-questions/day-02-strings/02_minimum_window_substring.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
// 02_minimum_window_substring.cpp
2-
// Problem: Minimum Window Substring
3-
// LeetCode: https://leetcode.com/problems/minimum-window-substring/
4-
// Author: DeveloperViraj (curated DSA set for Hacktoberfest 2025)
5-
// Compile: g++ -std=c++17 02_minimum_window_substring.cpp -o 02_minimum_window_substring
6-
// Run: ./02_minimum_window_substring
72
//
8-
// Summary:
9-
// Given strings S and T, find the smallest substring in S that contains all characters of T
10-
// (including multiplicity). If no such window exists, return an empty string.
3+
// 🔍 Algorithm: Minimum Window Substring
4+
// Description:
5+
// Finds the smallest substring in `source` that contains all
6+
// characters of `target` (including duplicates).
7+
// Uses a Sliding Window approach combined with frequency maps
8+
// to expand and contract the window optimally.
9+
//
10+
// Use Case:
11+
// Useful in text search problems, DNA sequence matching,
12+
// or when finding minimal segments containing specific data.
1113
//
12-
// Approach (sliding window + frequency maps):
13-
// 1. Build a frequency map for characters required by T.
14-
// 2. Expand 'right' pointer: add chars to current window counts.
15-
// 3. When the window satisfies all required counts (formed == required), try to shrink 'left'
16-
// to minimize the window while still satisfying the requirement.
17-
// 4. Track best (smallest) window found during the process.
14+
// Time Complexity: O(|S| + |T|)
15+
// Space Complexity: O(|T|)
1816
//
19-
// Time Complexity: O(|S| + |T|) average (each char processed a constant number of times).
20-
// Space Complexity: O(CHARSET) or O(|T|) for maps.
17+
// LeetCode: https://leetcode.com/problems/minimum-window-substring/
18+
2119

2220
#include <iostream>
2321
#include <string>

0 commit comments

Comments
 (0)