String LeetCode Problems: All 672, With Python Solutions
Every problem in this library that LeetCode tags String — 672 in total, 568 of them with a complete Python solution, a worked example and the time and space complexity of the approach.
- 672 problems
- 196 Easy
- 335 Medium
- 141 Hard
String problems by difficulty
Showing the first 200 of 672 problems. Problems with a complete Python solution are listed first, then by ascending problem number.
Easy (55)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 13 | Roman to Integer | Easy | Hash Table, Math, String |
| 14 | Longest Common Prefix | Easy | Trie, Array, String |
| 20 | Valid Parentheses | Easy | Stack, String |
| 28 | Find the Index of the First Occurrence in a String | Easy | Two Pointers, String, String Matching |
| 58 | Length of Last Word | Easy | String |
| 67 | Add Binary | Easy | Bit Manipulation, Math, String +1 |
| 125 | Valid Palindrome | Easy | Two Pointers, String |
| 168 | Excel Sheet Column Title | Easy | Math, String |
| 171 | Excel Sheet Column Number | Easy | Math, String |
| 205 | Isomorphic Strings | Easy | Hash Table, String |
| 242 | Valid Anagram | Easy | Hash Table, String, Sorting |
| 257 | Binary Tree Paths | Easy | Tree, Depth-First Search, String +2 |
| 290 | Word Pattern | Easy | Hash Table, String |
| 344 | Reverse String | Easy | Two Pointers, String |
| 345 | Reverse Vowels of a String | Easy | Two Pointers, String |
| 383 | Ransom Note | Easy | Hash Table, String, Counting |
| 387 | First Unique Character in a String | Easy | Queue, Hash Table, String +1 |
| 389 | Find the Difference | Easy | Bit Manipulation, Hash Table, String +1 |
| 392 | Is Subsequence | Easy | Two Pointers, String, Dynamic Programming |
| 405 | Convert a Number to Hexadecimal | Easy | Bit Manipulation, Math, String |
| 409 | Longest Palindrome | Easy | Greedy, Hash Table, String |
| 412 | Fizz Buzz | Easy | Math, String, Simulation |
| 415 | Add Strings | Easy | Math, String, Simulation |
| 434 | Number of Segments in a String | Easy | String |
| 459 | Repeated Substring Pattern | Easy | String, String Matching |
| 482 | License Key Formatting | Easy | String |
| 500 | Keyboard Row | Easy | Array, Hash Table, String |
| 504 | Base 7 | Easy | Math, String |
| 520 | Detect Capital | Easy | String |
| 521 | Longest Uncommon Subsequence I | Easy | String |
| 541 | Reverse String II | Easy | Two Pointers, String |
| 551 | Student Attendance Record I | Easy | String |
| 557 | Reverse Words in a String III | Easy | Two Pointers, String |
| 599 | Minimum Index Sum of Two Lists | Easy | Array, Hash Table, String |
| 657 | Robot Return to Origin | Easy | String, Simulation |
| 680 | Valid Palindrome II | Easy | Greedy, Two Pointers, String |
| 696 | Count Binary Substrings | Easy | Two Pointers, String |
| 709 | To Lower Case | Easy | String |
| 748 | Shortest Completing Word | Easy | Array, Hash Table, String |
| 771 | Jewels and Stones | Easy | Hash Table, String |
| 796 | Rotate String | Easy | String, String Matching |
| 804 | Unique Morse Code Words | Easy | Array, Hash Table, String |
| 806 | Number of Lines To Write String | Easy | Array, String |
| 819 | Most Common Word | Easy | Array, Hash Table, String +1 |
| 821 | Shortest Distance to a Character | Easy | Array, Two Pointers, String |
| 824 | Goat Latin | Easy | String |
| 830 | Positions of Large Groups | Easy | String |
| 844 | Backspace String Compare | Easy | Stack, Two Pointers, String +1 |
| 859 | Buddy Strings | Easy | Hash Table, String |
| 884 | Uncommon Words from Two Sentences | Easy | Hash Table, String, Counting |
| 917 | Reverse Only Letters | Easy | Two Pointers, String |
| 925 | Long Pressed Name | Easy | Two Pointers, String |
| 929 | Unique Email Addresses | Easy | Array, Hash Table, String |
| 942 | DI String Match | Easy | Greedy, Array, Two Pointers +1 |
| 944 | Delete Columns to Make Sorted | Easy | Array, String |
Medium (100)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 3 | Longest Substring Without Repeating Characters | Medium | Hash Table, String, Sliding Window |
| 5 | Longest Palindromic Substring | Medium | Two Pointers, String, Dynamic Programming |
| 6 | Zigzag Conversion | Medium | String |
| 8 | String to Integer (atoi) | Medium | String |
| 12 | Integer to Roman | Medium | Hash Table, Math, String |
| 17 | Letter Combinations of a Phone Number | Medium | Hash Table, String, Backtracking |
| 22 | Generate Parentheses | Medium | String, Dynamic Programming, Backtracking |
| 38 | Count and Say | Medium | String |
| 43 | Multiply Strings | Medium | Math, String, Simulation |
| 49 | Group Anagrams | Medium | Array, Hash Table, String +1 |
| 71 | Simplify Path | Medium | Stack, String |
| 72 | Edit Distance | Medium | String, Dynamic Programming |
| 79 | Word Search | Medium | Depth-First Search, Array, String +2 |
| 91 | Decode Ways | Medium | String, Dynamic Programming |
| 93 | Restore IP Addresses | Medium | String, Backtracking |
| 97 | Interleaving String | Medium | String, Dynamic Programming |
| 131 | Palindrome Partitioning | Medium | String, Dynamic Programming, Backtracking |
| 139 | Word Break | Medium | Trie, Memoization, Array +3 |
| 151 | Reverse Words in a String | Medium | Two Pointers, String |
| 165 | Compare Version Numbers | Medium | Two Pointers, String |
| 166 | Fraction to Recurring Decimal | Medium | Hash Table, Math, String |
| 179 | Largest Number | Medium | Greedy, Array, String +1 |
| 187 | Repeated DNA Sequences | Medium | Bit Manipulation, Hash Table, String +3 |
| 208 | Implement Trie (Prefix Tree) | Medium | Design, Trie, Hash Table +1 |
| 211 | Design Add and Search Words Data Structure | Medium | Depth-First Search, Design, Trie +1 |
| 227 | Basic Calculator II | Medium | Stack, Math, String |
| 241 | Different Ways to Add Parentheses | Medium | Recursion, Memoization, Math +2 |
| 299 | Bulls and Cows | Medium | Hash Table, String, Counting |
| 306 | Additive Number | Medium | String, Backtracking |
| 316 | Remove Duplicate Letters | Medium | Stack, Greedy, String +1 |
| 318 | Maximum Product of Word Lengths | Medium | Bit Manipulation, Array, String |
| 331 | Verify Preorder Serialization of a Binary Tree | Medium | Stack, Tree, String +1 |
| 385 | Mini Parser | Medium | Stack, Depth-First Search, String |
| 388 | Longest Absolute File Path | Medium | Stack, Depth-First Search, String |
| 394 | Decode String | Medium | Stack, Recursion, String |
| 395 | Longest Substring with At Least K Repeating Characters | Medium | Hash Table, String, Divide and Conquer +1 |
| 399 | Evaluate Division | Medium | Depth-First Search, Breadth-First Search, Union Find +4 |
| 402 | Remove K Digits | Medium | Stack, Greedy, String +1 |
| 423 | Reconstruct Original Digits from English | Medium | Hash Table, Math, String |
| 424 | Longest Repeating Character Replacement | Medium | Hash Table, String, Sliding Window |
| 433 | Minimum Genetic Mutation | Medium | Breadth-First Search, Hash Table, String |
| 438 | Find All Anagrams in a String | Medium | Hash Table, String, Sliding Window |
| 443 | String Compression | Medium | Two Pointers, String |
| 449 | Serialize and Deserialize BST | Medium | Tree, Depth-First Search, Breadth-First Search +4 |
| 451 | Sort Characters By Frequency | Medium | Hash Table, String, Bucket Sort +3 |
| 467 | Unique Substrings in Wraparound String | Medium | String, Dynamic Programming |
| 468 | Validate IP Address | Medium | String |
| 474 | Ones and Zeroes | Medium | Array, String, Dynamic Programming |
| 481 | Magical String | Medium | Two Pointers, String |
| 516 | Longest Palindromic Subsequence | Medium | String, Dynamic Programming |
| 522 | Longest Uncommon Subsequence II | Medium | Array, Hash Table, Two Pointers +2 |
| 524 | Longest Word in Dictionary through Deleting | Medium | Array, Two Pointers, String +1 |
| 535 | Encode and Decode TinyURL | Medium | Design, Hash Table, String +1 |
| 537 | Complex Number Multiplication | Medium | Math, String, Simulation |
| 539 | Minimum Time Difference | Medium | Array, Math, String +1 |
| 556 | Next Greater Element III | Medium | Math, Two Pointers, String |
| 567 | Permutation in String | Medium | Hash Table, Two Pointers, String +1 |
| 583 | Delete Operation for Two Strings | Medium | String, Dynamic Programming |
| 592 | Fraction Addition and Subtraction | Medium | Math, String, Simulation |
| 606 | Construct String from Binary Tree | Medium | Tree, Depth-First Search, String +1 |
| 609 | Find Duplicate File in System | Medium | Array, Hash Table, String |
| 640 | Solve the Equation | Medium | Math, String, Simulation |
| 647 | Palindromic Substrings | Medium | Two Pointers, String, Dynamic Programming |
| 648 | Replace Words | Medium | Trie, Array, Hash Table +1 |
| 649 | Dota2 Senate | Medium | Greedy, Queue, String |
| 676 | Implement Magic Dictionary | Medium | Depth-First Search, Design, Trie +2 |
| 677 | Map Sum Pairs | Medium | Design, Trie, Hash Table +1 |
| 678 | Valid Parenthesis String | Medium | Stack, Greedy, String +1 |
| 686 | Repeated String Match | Medium | String, String Matching |
| 692 | Top K Frequent Words | Medium | Trie, Array, Hash Table +5 |
| 712 | Minimum ASCII Delete Sum for Two Strings | Medium | String, Dynamic Programming |
| 720 | Longest Word in Dictionary | Medium | Trie, Array, Hash Table +2 |
| 721 | Accounts Merge | Medium | Depth-First Search, Breadth-First Search, Union Find +4 |
| 722 | Remove Comments | Medium | Array, String |
| 752 | Open the Lock | Medium | Breadth-First Search, Array, Hash Table +1 |
| 756 | Pyramid Transition Matrix | Medium | Bit Manipulation, Hash Table, String +1 |
| 763 | Partition Labels | Medium | Greedy, Hash Table, Two Pointers +1 |
| 767 | Reorganize String | Medium | Greedy, Hash Table, String +3 |
| 777 | Swap Adjacent in LR String | Medium | Two Pointers, String |
| 784 | Letter Case Permutation | Medium | Bit Manipulation, String, Backtracking |
| 791 | Custom Sort String | Medium | Hash Table, String, Sorting |
| 792 | Number of Matching Subsequences | Medium | Trie, Array, Hash Table +4 |
| 809 | Expressive Words | Medium | Array, Two Pointers, String |
| 811 | Subdomain Visit Count | Medium | Array, Hash Table, String +1 |
| 816 | Ambiguous Coordinates | Medium | String, Backtracking, Enumeration |
| 820 | Short Encoding of Words | Medium | Trie, Array, Hash Table +1 |
| 831 | Masking Personal Information | Medium | String |
| 833 | Find And Replace in String | Medium | Array, Hash Table, String +1 |
| 838 | Push Dominoes | Medium | Two Pointers, String, Dynamic Programming |
| 842 | Split Array into Fibonacci Sequence | Medium | String, Backtracking |
| 848 | Shifting Letters | Medium | Array, String, Prefix Sum |
| 856 | Score of Parentheses | Medium | Stack, String |
| 880 | Decoded String at Index | Medium | Stack, String |
| 890 | Find and Replace Pattern | Medium | Array, Hash Table, String |
| 893 | Groups of Special-Equivalent Strings | Medium | Array, Hash Table, String +1 |
| 916 | Word Subsets | Medium | Array, Hash Table, String |
| 921 | Minimum Add to Make Parentheses Valid | Medium | Stack, Greedy, String |
| 926 | Flip String to Monotone Increasing | Medium | String, Dynamic Programming |
| 937 | Reorder Data in Log Files | Medium | Array, String, Sorting |
| 949 | Largest Time for Given Digits | Medium | Array, String, Backtracking +1 |
Hard (45)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 10 | Regular Expression Matching | Hard | Recursion, String, Dynamic Programming |
| 30 | Substring with Concatenation of All Words | Hard | Hash Table, String, Sliding Window |
| 32 | Longest Valid Parentheses | Hard | Stack, String, Dynamic Programming |
| 44 | Wildcard Matching | Hard | Greedy, Recursion, String +1 |
| 65 | Valid Number | Hard | String |
| 68 | Text Justification | Hard | Array, String, Simulation |
| 76 | Minimum Window Substring | Hard | Hash Table, String, Sliding Window |
| 87 | Scramble String | Hard | String, Dynamic Programming |
| 115 | Distinct Subsequences | Hard | String, Dynamic Programming |
| 126 | Word Ladder II | Hard | Breadth-First Search, Hash Table, String +1 |
| 127 | Word Ladder | Hard | Breadth-First Search, Hash Table, String |
| 132 | Palindrome Partitioning II | Hard | String, Dynamic Programming |
| 140 | Word Break II | Hard | Trie, Memoization, Array +4 |
| 212 | Word Search II | Hard | Trie, Array, String +2 |
| 214 | Shortest Palindrome | Hard | String, String Matching, Hash Function +1 |
| 224 | Basic Calculator | Hard | Stack, Recursion, Math +1 |
| 273 | Integer to English Words | Hard | Recursion, Math, String |
| 282 | Expression Add Operators | Hard | Math, String, Backtracking |
| 297 | Serialize and Deserialize Binary Tree | Hard | Tree, Depth-First Search, Breadth-First Search +3 |
| 301 | Remove Invalid Parentheses | Hard | Breadth-First Search, String, Backtracking |
| 336 | Palindrome Pairs | Hard | Trie, Array, Hash Table +1 |
| 420 | Strong Password Checker | Hard | Greedy, String, Heap (Priority Queue) |
| 466 | Count The Repetitions | Hard | String, Dynamic Programming |
| 472 | Concatenated Words | Hard | Depth-First Search, Trie, Array +3 |
| 488 | Zuma Game | Hard | Stack, Breadth-First Search, Memoization +2 |
| 514 | Freedom Trail | Hard | Depth-First Search, Breadth-First Search, String +1 |
| 564 | Find the Closest Palindrome | Hard | Math, String |
| 591 | Tag Validator | Hard | Stack, String |
| 639 | Decode Ways II | Hard | String, Dynamic Programming |
| 664 | Strange Printer | Hard | String, Dynamic Programming |
| 691 | Stickers to Spell Word | Hard | Bit Manipulation, Memoization, Array +5 |
| 730 | Count Different Palindromic Subsequences | Hard | String, Dynamic Programming |
| 736 | Parse Lisp Expression | Hard | Stack, Recursion, Hash Table +1 |
| 745 | Prefix and Suffix Search | Hard | Design, Trie, Array +2 |
| 761 | Special Binary String | Hard | Recursion, String |
| 828 | Count Unique Characters of All Substrings of a Given String | Hard | Hash Table, String, Dynamic Programming |
| 839 | Similar String Groups | Hard | Depth-First Search, Breadth-First Search, Union Find +3 |
| 854 | K-Similar Strings | Hard | Breadth-First Search, Hash Table, String |
| 899 | Orderly Queue | Hard | Math, String, Sorting |
| 902 | Numbers At Most N Given Digit Set | Hard | Array, Math, String +2 |
| 903 | Valid Permutations for DI Sequence | Hard | String, Dynamic Programming, Prefix Sum |
| 906 | Super Palindromes | Hard | Math, String, Enumeration |
| 936 | Stamping The Sequence | Hard | Stack, Greedy, Queue +1 |
| 940 | Distinct Subsequences II | Hard | String, Dynamic Programming |
| 943 | Find the Shortest Superstring | Hard | Bit Manipulation, Array, String +2 |
Keep exploring
All LeetCode topicsEvery tag with a page of its own, with the number of problems behind each.LeetCode patternsThe techniques themselves, with a Python template and complexity for each.Curated study listsBlind 75, NeetCode 150 and three more, grouped by pattern.Easy problemsStart here when the data structure is new rather than the problem.
Other topics
- Array1,569
- Hash Table588
- Math485
- Dynamic Programming481
- Sorting392
- Greedy346
- Depth-First Search289
- Binary Search253
- Database249
- Tree225
- Breadth-First Search223
- Matrix216
- Two Pointers201
- Bit Manipulation194
- Binary Tree174
- Heap (Priority Queue)163
- Prefix Sum157
- Stack157
- Simulation144
- Graph138
- Counting126
- Design122
- Sliding Window116
- Backtracking105
When the String problem arrives live
Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.