String Problems for Coding Interviews
String problems test careful indexing and the right data structure: a hash map of counts, two pointers for palindromes, a sliding window for substrings and a stack for brackets. Know how your language stores strings, because immutability changes the cost of building them.
Common themes are anagrams, palindromes, longest substring conditions, parsing and matching. Practise stating the complexity of your solution and the edge cases (empty string, one character, repeated characters). Open any problem to run your code against test cases.
Coding problems
- Valid Parentheses (Basic)
- Longest Substring Without Repeats (Intermediate)
- Reverse String (Basic)
- First Unique Character (Basic)
- Valid Palindrome (Basic)
- Decode Ways (Intermediate)
- Longest Palindromic Substring (Intermediate)
- Valid Anagram (Basic)
- Ransom Note (Basic)
- Count Vowels (Basic)
- Caesar Cipher (Basic)
- Run-Length Encoding (Basic)
- Largest Odd Prefix (Basic)
- Repeated Substring Pattern (Intermediate)
- Reverse Words in a String (Basic)
- Rotate String Check (Basic)
- Reverse Vowels of a String (Basic)
- Roman to Integer (Intermediate)
- Excel Column Number (Basic)
- Add Binary (Basic)
- Common Prefix of Two Strings (Basic)
- Length of Last Word (Basic)
- Count Words (Basic)
- Longest Common Subsequence (Advanced)
- Edit Distance (Advanced)
- Palindrome Partitioning Min Cuts (Advanced)
- Longest Valid Parentheses (Advanced)
- Largest Number From Digits (Advanced)
- Balanced String Split (Basic)
- Score of Parentheses (Intermediate)
- Maximum Vowels in a Window (Intermediate)
- Greatest Common Divisor of Strings (Intermediate)
- Partition Labels (Intermediate)
- Sort Characters by Frequency (Intermediate)
- Longest Palindrome From Letters (Basic)
- Reverse Prefix Up To a Letter (Basic)
- Remove Outer Parentheses (Basic)
- Single Row Keyboard Typing Time (Basic)
- Find the Added Letter (Basic)
- Shortest Distance to a Character (Intermediate)
- Next Greatest Letter (Basic)
- Count Good Digit Strings (Intermediate)
- Count Substrings of Ones (Intermediate)
- Maximum Number of Balloons (Basic)
- Halves Are Alike (Basic)
- Make the String Good (Intermediate)
- Remove Invalid Parentheses (Intermediate)
- Valid Parenthesis With Wildcards (Advanced)
- Decode Repeated Strings (Intermediate)
- Is Subsequence (Basic)
- Count Asterisks Outside Bars (Basic)
- Minimum Time to Make Rope Colorful (Intermediate)
- Minimum Flips to Alternate Digits (Intermediate)
- Minimum Deletions for Unique Frequencies (Intermediate)
- Largest Triple of Equal Digits (Basic)
- Longest Substring With Two Letters (Intermediate)
- Longest Run After Replacements (Intermediate)
- Permutation Inside a String (Intermediate)
- Find All Anagram Starts (Intermediate)
- Zigzag Conversion (Intermediate)
Related
- Sliding window problems
- Dynamic programming problems
- Graph problems
- Practice coding problems online
- All interview question topics
Frequently asked questions
How do I get good at string problems?
Solve a few problems of each difficulty, name the pattern after you solve each one, and revisit the ones you needed hints for a week later. The list on this page is ordered so you can start with the basic ones.
Can I run string problems online here?
Yes. Every problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and six more languages, with no setup.