π€ Strings
Strings are arrays of characters with a few extra twists: immutability, character sets, and pattern matching. Most string problems reduce to sliding window, hashing, or two pointers.
This category contains 71 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.
π§ Key Patternsβ
- Sliding Window + Frequency Map β Longest/shortest substring with constraint on distinct chars or anagram windows.
- Two Pointers from Ends β Palindrome checks, reversing in place.
- Hashing & Frequency Counts β Anagram detection, group-by-signature.
- Expand Around Center β All palindromic substrings in .
- KMP / Z-Algorithm / Rolling Hash β Pattern matching in .
- Stack β Balanced parens, decode strings, simplify path.
β οΈ Common Pitfallsβ
- C#: avoid
string +=in a loop β useStringBuilder. - Char range assumption (
a..zvs full Unicode). Clarify before coding. - Off-by-one when comparing two pointers
i < jin palindrome expansion.
π Study Resourcesβ
πΊ Videosβ
π Booksβ
- Cracking the Coding Interview β Ch. 1 (Arrays & Strings)
- Algorithms β Sedgewick & Wayne β Ch. 5 (Strings)
π Articles & Referencesβ
π» All Strings Problemsβ
Add Strings
LeetCode 415 | Difficulty: Easy
Buddy Strings
LeetCode 889 | Difficulty: Easy
Check if One String Swap Can Make Strings Equal
LeetCode 1915 | Difficulty: Easy
Compare Version Numbers
LeetCode 165 | Difficulty: Medium
Count Binary Substrings
LeetCode 696 | Difficulty: Easy
Count Number of Homogenous Substrings
LeetCode 1885 | Difficulty: Medium
Decode String
LeetCode 394 | Difficulty: Medium
Determine if Two Strings Are Close
LeetCode 1777 | Difficulty: Medium
DI String Match
LeetCode 979 | Difficulty: Easy
Encode and Decode Strings
LeetCode Link
Evaluate Reverse Polish Notation
LeetCode 150 | Difficulty: Medium
Find First Palindromic String in the Array
LeetCode 2231 | Difficulty: Easy
Find Unique Binary String
LeetCode 2107 | Difficulty: Medium
First Unique Character in a String
LeetCode 387 | Difficulty: Easy
Group Anagrams
LeetCode 49 | Difficulty: Medium
Group Shifted Strings
LeetCode Link
Implement strStr()
LeetCode Link
Integer to English Words
LeetCode 273 | Difficulty: Hard
Isomorphic Strings
LeetCode 205 | Difficulty: Easy
Length of Last Word
LeetCode 58 | Difficulty: Easy
Longest Common Prefix
LeetCode 14 | Difficulty: Easy
Longest Happy String
LeetCode 1304 | Difficulty: Medium
Longest Palindrome
LeetCode 409 | Difficulty: Easy
Longest Palindromic Substring
LeetCode 5 | Difficulty: Medium
Longest Substring with At Least K Repeating Characters
LeetCode 395 | Difficulty: Medium
Longest Substring with At Most K Distinct Characters
LeetCode Link
Longest Substring with At Most Two Distinct Characters
LeetCode Link
Longest Substring Without Repeating Characters
LeetCode 3 | Difficulty: Medium
Longest Valid Parentheses
LeetCode 32 | Difficulty: Hard
Maximum Length of a Concatenated String with Unique Characters
LeetCode 1360 | Difficulty: Medium
Minimum Add to Make Parentheses Valid
LeetCode 957 | Difficulty: Medium
Minimum Insertion Steps to Make a String Palindrome
LeetCode 1437 | Difficulty: Hard
Minimum Insertions to Balance a Parentheses String
LeetCode 1648 | Difficulty: Medium
Minimum Number of Swaps to Make the String Balanced
LeetCode 2095 | Difficulty: Medium
Minimum Window Substring
LeetCode 76 | Difficulty: Hard
Most Common Word
LeetCode 837 | Difficulty: Easy
Multiply Strings
LeetCode 43 | Difficulty: Medium
Next Palindrome Using Same Digits
LeetCode Link
Number of Steps to Reduce a Number to Zero
LeetCode 1444 | Difficulty: Easy
Number of Substrings Containing All Three Characters
LeetCode 1460 | Difficulty: Medium
Number of Substrings With Only 1s
LeetCode 1636 | Difficulty: Medium
Palindrome Number
LeetCode 9 | Difficulty: Easy
Palindrome Permutation
LeetCode Link
Palindromic Substrings
LeetCode 647 | Difficulty: Medium
Permutations
Permutations of a String
Ransom Note
LeetCode 383 | Difficulty: Easy
Reorganize String
LeetCode 778 | Difficulty: Medium
Repeated Substring Pattern
LeetCode 459 | Difficulty: Easy
Reverse Nodes in k-Group
LeetCode 25 | Difficulty: Hard
Reverse String
LeetCode 344 | Difficulty: Easy
Reverse String II
LeetCode 541 | Difficulty: Easy
Reverse Vowels of a String
LeetCode 345 | Difficulty: Easy
Reverse Words in a String
LeetCode 151 | Difficulty: Medium
Reverse Words in a String II
LeetCode Link
Reverse Words in a String III
LeetCode 557 | Difficulty: Easy
Rotate String
LeetCode 812 | Difficulty: Easy
Simplify Path
LeetCode 71 | Difficulty: Medium
Smallest String Starting From Leaf
LeetCode 1030 | Difficulty: Medium
String Compression
LeetCode 443 | Difficulty: Medium
String to Integer (atoi)
LeetCode 8 | Difficulty: Medium
String Without AAA or BBB
LeetCode 1026 | Difficulty: Medium
Substring with Concatenation of All Words
LeetCode 30 | Difficulty: Hard
Substrings That Begin and End With the Same Letter
LeetCode Link
Text Justification
LeetCode 68 | Difficulty: Hard
Valid Anagram
LeetCode 242 | Difficulty: Easy
Valid Number
LeetCode 65 | Difficulty: Hard
Valid Palindrome
LeetCode 125 | Difficulty: Easy
Valid Palindrome II
LeetCode 680 | Difficulty: Easy
Valid Parentheses
LeetCode 20 | Difficulty: Easy
Valid Parenthesis String
LeetCode 678 | Difficulty: Medium
Zigzag Conversion
LeetCode 6 | Difficulty: Medium