LeetCodechevron_rightCategorieschevron_rightstring matching
label

string matching

33 problems
Easy: 10Medium: 8Hard: 15

string matching is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.

Interview Signal

Frequently tests problem modeling, edge handling, and verbal clarity.

Common Pitfall

Template-only answers break under follow-up questioning.

Practice Strategy

Practice in 3-5 problem rounds and always review complexity alternatives.

Recommended Progression

#TitleDifficulty
28

Find the Index of the First Occurrence in a String

Locate the first occurrence of a substring within a string using a two-pointer scanning strategy and invariant tracking …

Easy
214

Shortest Palindrome

The Shortest Palindrome problem asks to transform a string into a palindrome by adding characters at the beginning, with…

Hard
459

Repeated Substring Pattern

Check if a string can be constructed by repeating a substring using string matching techniques.

Easy
572

Subtree of Another Tree

Determine if one binary tree is an exact subtree of another by comparing structure and node values recursively.

Easy
686

Repeated String Match

Find the minimum number of repetitions of string a to make string b a substring of the repeated string a.

Medium
796

Rotate String

Determine if one string can be rotated into another by repeatedly shifting characters, leveraging string matching techni…

Easy
1023

Camelcase Matching

Camelcase Matching is a medium difficulty problem where you match queries to a given pattern by inserting lowercase lett…

Medium
1392

Longest Happy Prefix

Find the longest non-empty prefix of a string that also appears as its suffix, optimizing with rolling hash techniques.

Hard
1397

Find All Good Strings

Find all good strings between two given strings without including a specified evil substring using dynamic programming.

Hard
1408

String Matching in an Array

Identify all strings in an array that appear as substrings of other strings, focusing on array and string matching patte…

Easy
1455

Check If a Word Occurs As a Prefix of Any Word in a Sentence

Determine the first word in a sentence where a given searchWord is a prefix using two-pointer scanning with string match…

Easy
1668

Maximum Repeating Substring

Find the maximum number of times a given word repeats consecutively in a string using state transition dynamic programmi…

Easy
1764

Form Array by Concatenating Subarrays of Another Array

Determine if you can sequentially select disjoint subarrays from nums matching each group in order using two-pointer sca…

Medium
2185

Counting Words With a Given Prefix

Count how many words in a list start with a given prefix.

Easy
2223

Sum of Scores of Built Strings

Calculate the sum of scores of built strings by analyzing longest common prefixes with suffixes in a string using effici…

Hard
2301

Match Substring After Replacement

Determine if a target substring can appear in a string after optional character replacements using given mappings effici…

Hard
2430

Maximum Deletions on a String

Find the maximum number of deletions on a string using state transition dynamic programming and rolling hash techniques …

Hard
2851

String Transformation

Find how many ways string s can be transformed into string t in exactly k operations using suffix rotations.

Hard
3006

Find Beautiful Indices in the Given Array I

Identify all beautiful indices where substring a appears and a nearby substring b exists within distance k efficiently.

Medium
3008

Find Beautiful Indices in the Given Array II

Find Beautiful Indices in the Given Array II challenges you to use binary search and string matching techniques.

Hard
3029

Minimum Time to Revert Word to Initial State I

Determine the minimum seconds to revert a string to its original state using repeated prefix shifts of length k efficien…

Medium
3031

Minimum Time to Revert Word to Initial State II

The problem asks to calculate the minimum time required to revert a string to its initial state using specific operation…

Hard
3034

Number of Subarrays That Match a Pattern I

Count all subarrays in a given integer array that strictly follow a defined numeric pattern using rolling hash checks ef…

Medium
3036

Number of Subarrays That Match a Pattern II

Count subarrays matching a pattern of relative values using array transformation and rolling hash techniques.

Hard
3042

Count Prefix and Suffix Pairs I

Count all index pairs where one word is both a prefix and suffix of another, using efficient array and string checks.

Easy
3045

Count Prefix and Suffix Pairs II

Count the number of index pairs in a string array where one word is both a prefix and suffix of another using array and …

Hard
3291

Minimum Number of Valid Strings to Form Target I

Use dynamic programming to split target into the fewest prefixes that match any word prefix, while ruling out dead posit…

Medium
3292

Minimum Number of Valid Strings to Form Target II

Compute the minimum number of valid strings from an array needed to construct a given target string efficiently using dy…

Hard
3303

Find the Occurrence of First Almost Equal Substring

Locate the first substring in s that is almost equal to pattern by allowing at most one character mismatch efficiently.

Hard
3407

Substring Matching Pattern

Determine if a pattern containing a single wildcard can match any substring of a given string efficiently.

Easy
3455

Shortest Matching Substring

Find the shortest substring in a string that matches a pattern with exactly two wildcards efficiently using binary searc…

Hard
3474

Lexicographically Smallest Generated String

Generate the lexicographically smallest string by merging str1 and str2 using a greedy approach with invariant checks.

Hard
3529

Count Cells in Overlapping Horizontal and Vertical Substrings

Efficiently count grid cells appearing in both horizontal and vertical occurrences of a given string pattern using array…

Medium

Related Patterns

String Matching LeetCode Problems: 33 Solutions