|
1 | 1 | // 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 |
7 | 2 | // |
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. |
11 | 13 | // |
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|) |
18 | 16 | // |
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 | + |
21 | 19 |
|
22 | 20 | #include <iostream> |
23 | 21 | #include <string> |
|
0 commit comments