Pattern · 51 problems
String Interview Problems
Most string problems are array problems wearing a coat. I name the pattern underneath, and the text stops being scary.
Free: write the code and run it, no sign-up. Read the problem here; code it on a laptop.
When I reach for it
- The input is text and the answer is a count, a substring or a new string.
- You need to compare, reverse or rebuild characters.
- A window, two pointers or a count map hides inside.
Problems, easiest first
8 easy · 33 medium · 10 hard. Open one to read it, then write it in the free editor.
- Subtree of Another TreeeasyTreesBFS & DFS
- Valid AnagrameasyArrays & Hashing
- Valid PalindromeeasyTwo Pointers
- Valid ParentheseseasyStack
- Add BinaryeasyBit Manipulation
- Longest Palindrome LengtheasyGreedyArrays & Hashing
- Ransom NoteeasyArrays & Hashing
- Valid Palindrome IIeasyTwo Pointers
- Decode WaysmediumDynamic Programming
- Implement Trie (Prefix Tree)mediumTreesDesign
- Longest Common SubsequencemediumDynamic Programming
- Longest Palindromic SubstringmediumTwo PointersDynamic Programming
- Longest Repeating Character ReplacementmediumSliding WindowTwo Pointers
- Palindromic SubstringsmediumTwo PointersDynamic Programming
- Word SearchmediumBacktrackingBFS & DFS
- Design Add and Search Words Data StructuremediumTreesDesign
- Analytics: Longest Unique Session WindowmediumSliding Window
- Encode and Decode StringsmediumDesign
- Group AnagramsmediumArrays & Hashing
- Word BreakmediumTreesDynamic Programming
- Edit DistancemediumDynamic Programming
- Generate ParenthesesmediumBacktrackingDynamic Programming
- Interleaving StringmediumDynamic Programming
- Letter Combinations of a Phone NumbermediumBacktrackingArrays & Hashing
- Multiply Stringsmedium
Show the other 26 problems
- Palindrome PartitioningmediumBacktrackingDynamic Programming
- Partition LabelsmediumGreedyTwo Pointers
- Valid Parenthesis StringmediumStackGreedy
- Permutation in StringmediumSliding WindowTwo Pointers
- Accounts MergemediumGraphsBFS & DFS
- String to Integer Conversionmedium
- Find All Anagrams in a StringmediumSliding WindowArrays & Hashing
- Decode StringmediumStack
- Find All Possible Recipes from Given SuppliesmediumGraphsArrays & Hashing
- Minimum Remove to Make Valid ParenthesesmediumStackGreedy
- Reorganize StringmediumGreedyArrays & Hashing
- Replace WordsmediumArrays & Hashing
- Search Suggestions SystemmediumBinary SearchArrays & Hashing
- Top K Frequent WordsmediumHeapsArrays & Hashing
- Simplify PathmediumStack
- Web CrawlermediumDesignGraphs
- Word Search IIhardBacktrackingTrees
- Alien DictionaryhardGraphsBFS & DFS
- Minimum Window SubstringhardSliding WindowArrays & Hashing
- Distinct SubsequenceshardDynamic Programming
- Regular Expression MatchinghardBacktrackingDynamic Programming
- Word LadderhardGraphsBFS & DFS
- Basic CalculatorhardStack
- Encrypt and Decrypt StringshardDesignArrays & Hashing
- Word Break IIhardBacktrackingDynamic Programming
- Design Excel Sum FormulahardDesignGraphs
The idea
Ask which array pattern fits. A count map handles anagrams. Two pointers handle palindromes. A window handles the longest or shortest stretch.
Build results in a list and join once at the end. Strings are immutable in Python, Java and JavaScript, so adding to one in a loop copies it every time.
out = []
for ch in text:
if keep(ch):
out.append(transform(ch)) # build pieces in a list
return "".join(out) # join once at the endWhere it goes wrong
- Skipping the empty string and the one-character string.
- Not asking whether case, spaces and punctuation count.
- Slicing in a loop. Each slice copies, and the cost adds up.
Say this before you type. Say which array pattern the string is hiding before you touch a character.
Where Coco comes in
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.
Questions people ask
- Should I turn the string into a list?
- In Python, build a list of pieces and join once. In languages with mutable character arrays, edit in place instead.
- What do interviewers watch for on string problems?
- Edge cases and hidden cost. They want empty input handled and no quiet quadratic copying.
Meet these next
Fin and Coco are characters, not people. strongyes.io is independent. Leo builds it with AI agents.
