100 Problems on String Algorithms
Beginner (20 Problems)
1. Reverse a String - Write a function to reverse a string.
2. Check Palindrome - Determine if a string is a palindrome.
3. Count Vowels - Count the number of vowels in a given string.
4. String Length - Implement a function to return the length of a string without using
built-in functions.
5. Remove Duplicates - Remove duplicate characters from a string.
6. First Non-Repeating Character - Find the first non-repeating character in a string.
7. String to Integer (atoi) - Implement the atoi function.
8. Check Anagram - Check if two strings are anagrams of each other.
9. String Compression - Implement basic string compression.
10. Count Substrings - Count the number of substrings in a string.
11. Find the Character with Maximum Frequency - Find the character that appears
most frequently in a string.
12. Remove All Spaces - Remove all spaces from a string.
13. Capitalize First Letter of Each Word - Capitalize the first letter of each word in a
string.
14. Rotate String - Check if one string is a rotation of another.
15. Find the Longest Word in a String - Find the longest word in a given string.
16. Convert to Lowercase - Convert a string to lowercase without using built-in
functions.
17. Find All Occurrences of a Substring - Find all occurrences of a substring in a
string.
18. Check if Substring Exists - Check if a substring exists within a string.
19. Count the Number of Words - Count the number of words in a string.
20. Reverse Words in a String - Reverse the order of words in a string.
Intermediate (20 Problems)
21. Longest Palindromic Substring - Find the longest palindromic substring.
22. Substring with Concatenation of All Words - Find the starting indices of
substring(s) in a string.
23. Group Anagrams - Group anagrams from a list of strings.
24. Count and Say - Generate the n-th term of the count-and-say sequence.
25. Valid Parentheses - Check if the input string of parentheses is valid.
26. Implement strStr() - Implement strStr() function to find a substring.
27. Find the Index of First Non-Repeating Character - Find the index of the first
non-repeating character in a string.
28. Longest Common Prefix - Find the longest common prefix among an array of
strings.
29. Minimum Window Substring - Find the minimum window substring that contains all
characters of a target string.
30. Decode Ways - Determine the number of ways to decode a message.
31. Find Duplicate Subtrees - Find all duplicate subtrees in a binary tree (using strings
for serialization).
32. String Interleaving - Check if a string is formed by interleaving two other strings.
33. Compare Version Numbers - Compare two version numbers.
34. String Rotation - Check if one string is a rotation of another string using one pass.
35. Longest Repeating Character Replacement - Find the length of the longest
substring with at most k replacements.
36. Word Search - Find if a word exists in a 2D board.
37. Valid Anagram - Check if two strings are valid anagrams using sorting.
38. Palindrome Permutation - Check if a permutation of a string can form a palindrome.
39. Longest Substring Without Repeating Characters - Find the length of the longest
substring without repeating characters.
40. Reorganize String - Reorganize a string so that no two adjacent characters are the
same.
Advanced (20 Problems)
41. KMP Pattern Matching - Implement the KMP algorithm for substring search.
42. Rabin-Karp Algorithm - Implement the Rabin-Karp algorithm for substring search.
43. String Transformation - Transform one string into another using a set of operations.
44. Z Algorithm - Implement the Z algorithm for pattern matching.
45. Count Distinct Subsequences - Count distinct subsequences of a string.
46. Word Break Problem - Determine if a string can be segmented into a
space-separated list of words.
47. String Segmentation - Segment a string into valid dictionary words.
48. Find All Anagrams in a String - Find all starting indices of anagrams of a pattern in
a string.
49. Minimum Number of Steps to Make Two Strings Anagrams - Find the minimum
number of steps required to make two strings anagrams.
50. Longest Common Substring - Find the longest common substring between two
strings.
51. Longest Palindromic Subsequence - Find the longest palindromic subsequence in
a string.
52. Minimum Number of Deletions to Make a String Palindrome - Calculate the
minimum number of deletions needed to make a string palindrome.
53. Edit Distance - Find the minimum number of operations required to convert one
string into another.
54. Find All Permutations of a String - Generate all permutations of a string.
55. Find the Smallest Window in a String - Find the smallest window in a string that
contains all characters of another string.
56. Longest Palindromic Subsequence - Find the longest palindromic subsequence.
57. Count All Distinct Subsequences - Count all distinct subsequences of a string.
58. Transform to Palindrome - Check if a string can be transformed into a palindrome
using a limited number of character changes.
59. String Compression using RLE - Implement run-length encoding.
60. Subarray with K Different Integers - Count the number of subarrays with exactly k
different integers.
Expert (20 Problems)
61. Suffix Array Construction - Construct the suffix array of a string.
62. Longest Common Substring with Suffix Array - Find the longest common
substring using suffix arrays.
63. Suffix Tree Construction - Build a suffix tree for a given string.
64. Longest Repeated Substring - Find the longest repeated substring in a string.
65. Palindrome Partitioning - Partition a string such that every substring is a
palindrome.
66. Longest Valid Parentheses - Find the length of the longest valid parentheses
substring.
67. Regular Expression Matching - Implement a function that supports regular
expression matching.
68. Find the Minimum Window Substring - Find the smallest substring containing all
characters of another string.
69. Count Palindromic Substrings - Count all palindromic substrings in a string.
70. Number of Distinct Subsequences - Count the number of distinct subsequences of
a string.
71. Wildcard Matching - Implement wildcard pattern matching with * and ?.
72. Find the Shortest Palindrome - Given a string, find the shortest palindrome by
adding characters in front of it.
73. Construct String from Binary Tree - Construct a string from a binary tree in
preorder traversal.
74. Valid Parenthesis String - Check if a string with (, ), and * can form a valid
parentheses string.
75. Subarray Product Less Than K - Count the number of contiguous subarrays where
the product is less than k.
76. Minimum Operations to Make a String Palindrome - Find the minimum number of
operations needed to make a string palindrome.
77. Minimum Number of Parentheses to Add - Find the minimum number of
parentheses to add to make a string valid.
78. Check if One String is a Subsequence of Another - Check if one string is a
subsequence of another.
79. Count Distinct Substrings - Count the number of distinct substrings in a string.
80. Find the First Unique Character - Find the index of the first unique character in a
string.
Mastery (20 Problems)
81. KMP Algorithm Implementation - Implement the KMP algorithm for pattern
searching.
82. Aho-Corasick Algorithm - Implement the Aho-Corasick algorithm for multiple
pattern searching.
83. Longest Common Substring with 3 Strings - Find the longest common substring
among three strings.
84. K-th Smallest Element in a String Array - Find the k-th smallest element in a string
array based on length.
85. Find Substring with All Characters of Another String - Find a substring containing
all characters of another string.
86. Determine if a String is an E-Distance Palindrome - Check if a string can be a
palindrome with a limited number of deletions.
87. Find Maximum Length of a String Chain - Find the maximum length of a string
chain where each string can only differ by one letter.
88. Count Distinct Palindromic Substrings - Count distinct palindromic substrings.
89. Sparse Table for String Matching - Build a sparse table for string matching.
90. Longest Repeating Substring Using Suffix Array - Find the longest repeating
substring using suffix array and LCP.
91. Transform to an Anagram - Check if one string can be transformed into another by
rearranging characters.
92. Find the Number of Ways to Form a Target String - Count the number of ways to
form a target string using characters from another string.
93. String Reversal with Stack - Reverse a string using a stack.
94. Check if a String is a Valid Number - Validate if a given string is a number.
95. Longest Substring with At Most K Distinct Characters - Find the length of the
longest substring with at most k distinct characters.
96. Find the First Repeating Character in a String - Find the first repeating character
in a string.
97. Transform a String into Another with Minimum Operations - Calculate the
minimum operations to transform one string into another.
98. Serialize and Deserialize Binary Tree - Serialize and deserialize a binary tree using
strings.
99. Edit Distance between Two Strings - Calculate the edit distance between two
strings.
100. Lexicographical Order of Subsequences - Find the subsequence of a string in
lexicographical order.
Tips for Practice
● Start from the Basics: Focus on beginner problems to build your foundation.
● Time Management: Set a time limit for each problem to simulate real interview
conditions.
● Understand the Concepts: Don't just solve the problems—make sure you
understand the underlying concepts and algorithms.
● Review and Revise: After solving, review your solutions and optimize them if
possible.
● Mock Interviews: Consider doing mock interviews with peers or using platforms that
offer this service to improve your problem-solving speed under pressure.
Feel free to ask if you need detailed explanations or solutions for specific problems!