Interactive visualization of string structure, two-pointer and sliding-window patterns, pattern matching, and interview problems.
Learning Progress. Work top to bottom: theory → operations → the interactive visualizer → patterns → cheat sheet → interview prep. Pin the visualizer (button top-right of the panel) to keep it on screen while you read.
Theory & Fundamentals
What is a String?
A String is a sequence of characters, stored as a contiguous array of code units. In C it's null-terminated ('\0'); in C++ std::string tracks its own length and grows dynamically.
Because it's an array under the hood, indexed access is O(1), but insertion/deletion in the middle is O(n) and (in many languages) strings are immutable, so edits create new strings.
Layout
// "hello" as a char array
Index: 0 1 2 3 4 5
Char: h e l l o \0
// s[i] = base + i * sizeof(char) char c = s[1]; // 'e' — O(1)
Why Strings matter. Text is everywhere: parsing, search, tokenization, DNA sequences, URLs, JSON. String problems dominate interviews because they combine arrays, hashing, two pointers, sliding windows, and DP.
Key techniques
↔️
Two Pointers
Pointers from both ends (palindrome, reverse) or same direction (dedup).
Use: palindrome, reverse, compare.
🪟
Sliding Window
Expand/contract a window over the string tracking a frequency condition.
Use: longest substring, anagrams, min window.
🔤
Frequency / Hashing
Count characters in an int[26]/int[128] array or hash map.
// Palindrome — two pointers O(n)boolisPalindrome(string s) {
int i = 0, j = s.size() - 1;
while (i < j) if (s[i++] != s[j--]) returnfalse;
returntrue;
}
// Valid anagram — frequency O(n)boolisAnagram(string a, string b) {
if (a.size() != b.size()) returnfalse;
int f[26] = {0};
for (char c : a) f[c - 'a']++;
for (char c : b) if (--f[c - 'a'] < 0) returnfalse;
returntrue;
}
// Longest substring w/o repeating — sliding window O(n)intlengthOfLongest(string s) {
vector<int> last(128, -1);
int left = 0, best = 0;
for (int r = 0; r < s.size(); r++) {
if (last[s[r]] >= left) left = last[s[r]] + 1;
last[s[r]] = r;
best = max(best, r - left + 1);
}
return best;
}
Interactive String Visualization
Interactive String Visualization
CharPointer iPointer jWindowMatchMismatch
Idle
Current operation details
Operation
—
Pointer(s)
—
Best / Result
—
Steps
0
taken
Comparisons
0
checks
Window len
0
current
Length
0
chars
Step — of —
Select a scenario above, or use the manual controls, then press Play.
Manual controls — enter your own string
✓ Done
Speed
Step-by-step operation log
Step
i
j
Action
State
Run a scenario to populate the log.
Key Patterns
Sliding window. Expand the right edge to include a new char; when the window breaks the condition (repeat char, too many distinct), shrink from the left. Track the best window length. Most "longest/shortest substring" problems are O(n) this way.
Frequency arrays beat hash maps for fixed alphabets. An int[26] or int[128] is faster and simpler than a hash map for lowercase/ASCII problems — anagrams, first unique char, ransom note.
Cheat Sheet
Task
Technique
Time
Notes
Palindrome check
Two pointers
O(n)
Compare ends inward
Reverse
Two pointers
O(n)
Swap in place
Anagram
Frequency array
O(n)
int[26] counts
Longest substring
Sliding window
O(n)
Expand/contract
Substring search
KMP / Z
O(n+m)
Prefix function
Edit distance / LCS
2D DP
O(n·m)
Tabulation
Learning Roadmap
1
String Basics
std::string API, indexing, substr, find, immutability vs mutability.
~2 hours
2
Two Pointers & Frequency
Palindrome, reverse, anagram, first unique char, valid palindrome II.
~3 hours
3
Sliding Window
Longest substring without repeats, min window substring, find all anagrams.
~4 hours
4
Pattern Matching
KMP prefix function, Z-algorithm, Rabin-Karp rolling hash.
~4 hours
5
String DP
Edit distance, longest common subsequence, palindromic substrings, regex matching.
~4 hours
Interview Preparation
Valid Palindrome
Two pointers from both ends, skip non-alphanumerics, compare case-insensitively. O(n)/O(1).
Two Pointers
Longest Substring Without Repeating
Sliding window with last-seen index array; jump left past the repeat. O(n).
Window
Group Anagrams
Key each word by its sorted form (or char-count signature) into a hash map. O(n·k log k).
Hashing
Minimum Window Substring
Two frequency maps (need/have) and a shrinking window once all chars are covered. O(n).
Window
Practice Problems
EasyValid PalindromeTwo Pointers
EasyValid AnagramFrequency
EasyReverse StringTwo Pointers
MediumLongest Substring Without RepeatingWindow
MediumGroup AnagramsHashing
MediumLongest Palindromic SubstringExpand Center
HardMinimum Window SubstringWindow
HardEdit DistanceDP
Key Takeaways
🔤Strings are char arrays: O(1) index, O(n) middle edits, often immutable — avoid naive concatenation in loops.
🪟Sliding window: the workhorse for "longest/shortest substring" problems, turning O(n²) into O(n).
🔢Frequency arrays: int[26]/int[128] beats a hash map for fixed alphabets — anagrams, uniqueness, counting.
🔎Pattern matching & DP: KMP/Z for search in O(n+m); 2D DP for edit distance, LCS, and regex.