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)

#ProblemDifficultyTopics
13Roman to IntegerEasyHash Table, Math, String
14Longest Common PrefixEasyTrie, Array, String
20Valid ParenthesesEasyStack, String
28Find the Index of the First Occurrence in a StringEasyTwo Pointers, String, String Matching
58Length of Last WordEasyString
67Add BinaryEasyBit Manipulation, Math, String +1
125Valid PalindromeEasyTwo Pointers, String
168Excel Sheet Column TitleEasyMath, String
171Excel Sheet Column NumberEasyMath, String
205Isomorphic StringsEasyHash Table, String
242Valid AnagramEasyHash Table, String, Sorting
257Binary Tree PathsEasyTree, Depth-First Search, String +2
290Word PatternEasyHash Table, String
344Reverse StringEasyTwo Pointers, String
345Reverse Vowels of a StringEasyTwo Pointers, String
383Ransom NoteEasyHash Table, String, Counting
387First Unique Character in a StringEasyQueue, Hash Table, String +1
389Find the DifferenceEasyBit Manipulation, Hash Table, String +1
392Is SubsequenceEasyTwo Pointers, String, Dynamic Programming
405Convert a Number to HexadecimalEasyBit Manipulation, Math, String
409Longest PalindromeEasyGreedy, Hash Table, String
412Fizz BuzzEasyMath, String, Simulation
415Add StringsEasyMath, String, Simulation
434Number of Segments in a StringEasyString
459Repeated Substring PatternEasyString, String Matching
482License Key FormattingEasyString
500Keyboard RowEasyArray, Hash Table, String
504Base 7EasyMath, String
520Detect CapitalEasyString
521Longest Uncommon Subsequence IEasyString
541Reverse String IIEasyTwo Pointers, String
551Student Attendance Record IEasyString
557Reverse Words in a String IIIEasyTwo Pointers, String
599Minimum Index Sum of Two ListsEasyArray, Hash Table, String
657Robot Return to OriginEasyString, Simulation
680Valid Palindrome IIEasyGreedy, Two Pointers, String
696Count Binary SubstringsEasyTwo Pointers, String
709To Lower CaseEasyString
748Shortest Completing WordEasyArray, Hash Table, String
771Jewels and StonesEasyHash Table, String
796Rotate StringEasyString, String Matching
804Unique Morse Code WordsEasyArray, Hash Table, String
806Number of Lines To Write StringEasyArray, String
819Most Common WordEasyArray, Hash Table, String +1
821Shortest Distance to a CharacterEasyArray, Two Pointers, String
824Goat LatinEasyString
830Positions of Large GroupsEasyString
844Backspace String CompareEasyStack, Two Pointers, String +1
859Buddy StringsEasyHash Table, String
884Uncommon Words from Two SentencesEasyHash Table, String, Counting
917Reverse Only LettersEasyTwo Pointers, String
925Long Pressed NameEasyTwo Pointers, String
929Unique Email AddressesEasyArray, Hash Table, String
942DI String MatchEasyGreedy, Array, Two Pointers +1
944Delete Columns to Make SortedEasyArray, String

Medium (100)

#ProblemDifficultyTopics
3Longest Substring Without Repeating CharactersMediumHash Table, String, Sliding Window
5Longest Palindromic SubstringMediumTwo Pointers, String, Dynamic Programming
6Zigzag ConversionMediumString
8String to Integer (atoi)MediumString
12Integer to RomanMediumHash Table, Math, String
17Letter Combinations of a Phone NumberMediumHash Table, String, Backtracking
22Generate ParenthesesMediumString, Dynamic Programming, Backtracking
38Count and SayMediumString
43Multiply StringsMediumMath, String, Simulation
49Group AnagramsMediumArray, Hash Table, String +1
71Simplify PathMediumStack, String
72Edit DistanceMediumString, Dynamic Programming
79Word SearchMediumDepth-First Search, Array, String +2
91Decode WaysMediumString, Dynamic Programming
93Restore IP AddressesMediumString, Backtracking
97Interleaving StringMediumString, Dynamic Programming
131Palindrome PartitioningMediumString, Dynamic Programming, Backtracking
139Word BreakMediumTrie, Memoization, Array +3
151Reverse Words in a StringMediumTwo Pointers, String
165Compare Version NumbersMediumTwo Pointers, String
166Fraction to Recurring DecimalMediumHash Table, Math, String
179Largest NumberMediumGreedy, Array, String +1
187Repeated DNA SequencesMediumBit Manipulation, Hash Table, String +3
208Implement Trie (Prefix Tree)MediumDesign, Trie, Hash Table +1
211Design Add and Search Words Data StructureMediumDepth-First Search, Design, Trie +1
227Basic Calculator IIMediumStack, Math, String
241Different Ways to Add ParenthesesMediumRecursion, Memoization, Math +2
299Bulls and CowsMediumHash Table, String, Counting
306Additive NumberMediumString, Backtracking
316Remove Duplicate LettersMediumStack, Greedy, String +1
318Maximum Product of Word LengthsMediumBit Manipulation, Array, String
331Verify Preorder Serialization of a Binary TreeMediumStack, Tree, String +1
385Mini ParserMediumStack, Depth-First Search, String
388Longest Absolute File PathMediumStack, Depth-First Search, String
394Decode StringMediumStack, Recursion, String
395Longest Substring with At Least K Repeating CharactersMediumHash Table, String, Divide and Conquer +1
399Evaluate DivisionMediumDepth-First Search, Breadth-First Search, Union Find +4
402Remove K DigitsMediumStack, Greedy, String +1
423Reconstruct Original Digits from EnglishMediumHash Table, Math, String
424Longest Repeating Character ReplacementMediumHash Table, String, Sliding Window
433Minimum Genetic MutationMediumBreadth-First Search, Hash Table, String
438Find All Anagrams in a StringMediumHash Table, String, Sliding Window
443String CompressionMediumTwo Pointers, String
449Serialize and Deserialize BSTMediumTree, Depth-First Search, Breadth-First Search +4
451Sort Characters By FrequencyMediumHash Table, String, Bucket Sort +3
467Unique Substrings in Wraparound StringMediumString, Dynamic Programming
468Validate IP AddressMediumString
474Ones and ZeroesMediumArray, String, Dynamic Programming
481Magical StringMediumTwo Pointers, String
516Longest Palindromic SubsequenceMediumString, Dynamic Programming
522Longest Uncommon Subsequence IIMediumArray, Hash Table, Two Pointers +2
524Longest Word in Dictionary through DeletingMediumArray, Two Pointers, String +1
535Encode and Decode TinyURLMediumDesign, Hash Table, String +1
537Complex Number MultiplicationMediumMath, String, Simulation
539Minimum Time DifferenceMediumArray, Math, String +1
556Next Greater Element IIIMediumMath, Two Pointers, String
567Permutation in StringMediumHash Table, Two Pointers, String +1
583Delete Operation for Two StringsMediumString, Dynamic Programming
592Fraction Addition and SubtractionMediumMath, String, Simulation
606Construct String from Binary TreeMediumTree, Depth-First Search, String +1
609Find Duplicate File in SystemMediumArray, Hash Table, String
640Solve the EquationMediumMath, String, Simulation
647Palindromic SubstringsMediumTwo Pointers, String, Dynamic Programming
648Replace WordsMediumTrie, Array, Hash Table +1
649Dota2 SenateMediumGreedy, Queue, String
676Implement Magic DictionaryMediumDepth-First Search, Design, Trie +2
677Map Sum PairsMediumDesign, Trie, Hash Table +1
678Valid Parenthesis StringMediumStack, Greedy, String +1
686Repeated String MatchMediumString, String Matching
692Top K Frequent WordsMediumTrie, Array, Hash Table +5
712Minimum ASCII Delete Sum for Two StringsMediumString, Dynamic Programming
720Longest Word in DictionaryMediumTrie, Array, Hash Table +2
721Accounts MergeMediumDepth-First Search, Breadth-First Search, Union Find +4
722Remove CommentsMediumArray, String
752Open the LockMediumBreadth-First Search, Array, Hash Table +1
756Pyramid Transition MatrixMediumBit Manipulation, Hash Table, String +1
763Partition LabelsMediumGreedy, Hash Table, Two Pointers +1
767Reorganize StringMediumGreedy, Hash Table, String +3
777Swap Adjacent in LR StringMediumTwo Pointers, String
784Letter Case PermutationMediumBit Manipulation, String, Backtracking
791Custom Sort StringMediumHash Table, String, Sorting
792Number of Matching SubsequencesMediumTrie, Array, Hash Table +4
809Expressive WordsMediumArray, Two Pointers, String
811Subdomain Visit CountMediumArray, Hash Table, String +1
816Ambiguous CoordinatesMediumString, Backtracking, Enumeration
820Short Encoding of WordsMediumTrie, Array, Hash Table +1
831Masking Personal InformationMediumString
833Find And Replace in StringMediumArray, Hash Table, String +1
838Push DominoesMediumTwo Pointers, String, Dynamic Programming
842Split Array into Fibonacci SequenceMediumString, Backtracking
848Shifting LettersMediumArray, String, Prefix Sum
856Score of ParenthesesMediumStack, String
880Decoded String at IndexMediumStack, String
890Find and Replace PatternMediumArray, Hash Table, String
893Groups of Special-Equivalent StringsMediumArray, Hash Table, String +1
916Word SubsetsMediumArray, Hash Table, String
921Minimum Add to Make Parentheses ValidMediumStack, Greedy, String
926Flip String to Monotone IncreasingMediumString, Dynamic Programming
937Reorder Data in Log FilesMediumArray, String, Sorting
949Largest Time for Given DigitsMediumArray, String, Backtracking +1

Hard (45)

#ProblemDifficultyTopics
10Regular Expression MatchingHardRecursion, String, Dynamic Programming
30Substring with Concatenation of All WordsHardHash Table, String, Sliding Window
32Longest Valid ParenthesesHardStack, String, Dynamic Programming
44Wildcard MatchingHardGreedy, Recursion, String +1
65Valid NumberHardString
68Text JustificationHardArray, String, Simulation
76Minimum Window SubstringHardHash Table, String, Sliding Window
87Scramble StringHardString, Dynamic Programming
115Distinct SubsequencesHardString, Dynamic Programming
126Word Ladder IIHardBreadth-First Search, Hash Table, String +1
127Word LadderHardBreadth-First Search, Hash Table, String
132Palindrome Partitioning IIHardString, Dynamic Programming
140Word Break IIHardTrie, Memoization, Array +4
212Word Search IIHardTrie, Array, String +2
214Shortest PalindromeHardString, String Matching, Hash Function +1
224Basic CalculatorHardStack, Recursion, Math +1
273Integer to English WordsHardRecursion, Math, String
282Expression Add OperatorsHardMath, String, Backtracking
297Serialize and Deserialize Binary TreeHardTree, Depth-First Search, Breadth-First Search +3
301Remove Invalid ParenthesesHardBreadth-First Search, String, Backtracking
336Palindrome PairsHardTrie, Array, Hash Table +1
420Strong Password CheckerHardGreedy, String, Heap (Priority Queue)
466Count The RepetitionsHardString, Dynamic Programming
472Concatenated WordsHardDepth-First Search, Trie, Array +3
488Zuma GameHardStack, Breadth-First Search, Memoization +2
514Freedom TrailHardDepth-First Search, Breadth-First Search, String +1
564Find the Closest PalindromeHardMath, String
591Tag ValidatorHardStack, String
639Decode Ways IIHardString, Dynamic Programming
664Strange PrinterHardString, Dynamic Programming
691Stickers to Spell WordHardBit Manipulation, Memoization, Array +5
730Count Different Palindromic SubsequencesHardString, Dynamic Programming
736Parse Lisp ExpressionHardStack, Recursion, Hash Table +1
745Prefix and Suffix SearchHardDesign, Trie, Array +2
761Special Binary StringHardRecursion, String
828Count Unique Characters of All Substrings of a Given StringHardHash Table, String, Dynamic Programming
839Similar String GroupsHardDepth-First Search, Breadth-First Search, Union Find +3
854K-Similar StringsHardBreadth-First Search, Hash Table, String
899Orderly QueueHardMath, String, Sorting
902Numbers At Most N Given Digit SetHardArray, Math, String +2
903Valid Permutations for DI SequenceHardString, Dynamic Programming, Prefix Sum
906Super PalindromesHardMath, String, Enumeration
936Stamping The SequenceHardStack, Greedy, Queue +1
940Distinct Subsequences IIHardString, Dynamic Programming
943Find the Shortest SuperstringHardBit Manipulation, Array, String +2

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.