📘 DSA: Strings Learning Roadmap (Beginner → Advanced)
1. Basics of Strings (Foundations)
These are must-know before solving problems.
-
Mutable vs Immutable (C++: std::string is mutable)
-
Character arrays vs string class
-
Common operations: length, substring, concatenation, comparison
-
ASCII & Unicode basics
-> Click here for more details
🔍 2. Two Pointers on Strings
Used for many interview problems (palindrome, substring checks).
Key patterns:
-
Move pointers from left & right
-
Shrink/expand window on conditions
🪟 3. Sliding Window (Very Important)
Strings + Sliding Window = 20% of interview questions.
Understand two types:
🔸 Fixed Window
E.g., find anagrams of a pattern.
🔸 Variable Window
E.g., longest substring with K distinct characters.
🧮 4. Hashing for Strings
Character frequency arrays
-
For lowercase → size 26
-
For ASCII → size 256
-
For Unicode → use hash maps
Rolling Hash / Rabin-Karp
-
Efficient substring search
-
Used for detecting duplicate substrings, plagiarism, etc.
Interview problems:
-
Rabin-Karp implementation
-
Longest duplicate substring (binary search + rolling hash)
🔤 5. Pattern Matching Algorithms
KMP (Knuth–Morris–Pratt)
Why important?
-
Used for substring search in O(n + m)
-
LPS array is commonly asked in interviews.
Z-Algorithm
-
Alternate fast pattern matching
-
Helps in string prefix-based problems
Trie (String Tree)
- Useful for autocomplete, prefix search, dictionary problems
Problems:
-
Word search
-
Longest common prefix
-
Implement Trie
6. Advanced String Topics
These help in elite interviews.
Suffix Array
-
Used for lexicographical ordering of suffixes
-
Applications: substring search, LCP computation
Suffix Tree / Compressed Trie
-
Extremely fast substring search
-
Rare but high-reward for deep interviews
Manacher’s Algorithm
- O(n) longest palindromic substring
📝 Must Do String Problems
🔹 Level 1 – Easy
-
Reverse string
-
Palindrome check
-
Count occurrences of characters
-
Remove duplicates
-
String compression
🔹 Level 2 – Medium
-
Longest substring without repeating
-
Longest palindromic substring
-
Group anagrams
-
Valid parentheses
-
Multiply large numbers (string simulation)
-
Leetcode 271. Encode and Decode Strings{Premium Problem} - My Leetcode Solution link
- If you can’t see the problem, Click Here
-
Leetcode 647. Palindromic Substrings - My Leetcode Solution link
-
Leetcode 5. Longest Palindromic Substring - My Leetcode Solution link
🔹 Level 3 – Hard
-
Minimum window substring
-
Word break (DP + String)
-
Regular expression matching (DP)
-
Wildcard matching
-
KMP + Z-algorithm applications
-
Longest duplicate substring (binary search + hash)
-
Leetcode 647. Palindromic Substrings - My Leetcode Solution link