Skip to main content

Pattern · 42 problems

String Interview Problems

Most string problems are array problems wearing a coat. I name the pattern underneath, and the text stops being scary.

Get the link for your laptop

Free: write the code and run it, no sign-up.

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

7 easy · 26 medium · 9 hard. Open one to read it, then write it in the free editor.

  1. Subtree of Another TreeeasyTreesBFS & DFS
  2. Valid AnagrameasyArrays & Hashing
  3. Valid PalindromeeasyTwo Pointers
  4. Valid ParentheseseasyStack
  5. Add BinaryeasyBit Manipulation
  6. Longest Palindrome LengtheasyGreedyArrays & Hashing
  7. Ransom NoteeasyArrays & Hashing
  8. Decode WaysmediumDynamic Programming
  9. Implement Trie (Prefix Tree)mediumTreesDesign
  10. Longest Common SubsequencemediumDynamic Programming
  11. Longest Palindromic SubstringmediumTwo PointersDynamic Programming
  12. Longest Repeating Character ReplacementmediumSliding WindowTwo Pointers
  13. Palindromic SubstringsmediumTwo PointersDynamic Programming
  14. Word SearchmediumBacktrackingBFS & DFS
  15. Design Add and Search Words Data StructuremediumTreesDesign
  16. Analytics: Longest Unique Session WindowmediumSliding Window
  17. Encode and Decode StringsmediumDesign
  18. Group AnagramsmediumArrays & Hashing
  19. Word BreakmediumTreesDynamic Programming
  20. Edit DistancemediumDynamic Programming
  21. Generate ParenthesesmediumBacktrackingDynamic Programming
  22. Interleaving StringmediumDynamic Programming
  23. Letter Combinations of a Phone NumbermediumBacktrackingArrays & Hashing
  24. Multiply Stringsmedium
  25. Palindrome PartitioningmediumBacktrackingDynamic Programming
Show the other 17 problems
  1. Partition LabelsmediumGreedyTwo Pointers
  2. Valid Parenthesis StringmediumStackGreedy
  3. Permutation in StringmediumSliding WindowTwo Pointers
  4. Accounts MergemediumGraphsBFS & DFS
  5. String to Integer Conversionmedium
  6. Find All Anagrams in a StringmediumSliding WindowArrays & Hashing
  7. Simplify PathmediumStack
  8. Web CrawlermediumGraphsDesign
  9. Word Search IIhardBacktrackingTrees
  10. Alien DictionaryhardGraphsBFS & DFS
  11. Minimum Window SubstringhardSliding WindowArrays & Hashing
  12. Distinct SubsequenceshardDynamic Programming
  13. Regular Expression MatchinghardBacktrackingDynamic Programming
  14. Word LadderhardGraphsBFS & DFS
  15. Basic CalculatorhardStack
  16. Encrypt and Decrypt StringshardDesignArrays & Hashing
  17. Design Excel Sum FormulahardGraphsDesign

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 end
Collect the pieces, then join once. The loop stays linear and the intent stays readable. Python shown; the idea carries to every language in the editor.

Where 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, and to talk with her for one hour. After that, talking comes with the $79 pack. 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.