๐ Practice Problems
โก View All Strings Problems โ9 curated problems with solutions โข Easy to Hard difficulty
๐ Table of Contents
- ๐ DSA: Strings Learning Roadmap (Beginner โ Advanced)
1.1. 1. Basics of Strings (Foundations)
1.2. ๐ 2. Two Pointers on Strings
1.3. ๐ช 3. Sliding Window (Very Important)
1.4. ๐งฎ 4. Hashing for Strings
1.5. ๐ค 5. Pattern Matching Algorithms
1.6.
6. Advanced String Topics
- ๐ Must Do String Problems 2.1. ๐น Level 1 โ Easy 2.2. ๐น Level 2 โ Medium 2.3. ๐น Level 3 โ Hard
๐ฏ Main Topics Covered
- 1 Basics of Strings Foundations
- 2 Two Pointers on Strings
- 3 Sliding Window Very Important
- 4 Hashing for Strings
- 5 Pattern Matching Algorithms
- img src assetsiconspuzzlesvg relative_url classinline-icon alt 6 Advanced String Topics
- Level 1 Easy
- Level 2 Medium โฆ and 1 more
๐ 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