String in Data Structure
Last Updated :
09 Jul, 2025
Improve
A string is a sequence of characters. The following facts make string an interesting data structure.
- Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.
- Strings are immutable in programming languages like Java, Python, JavaScript and C#.
- Many String Problems can optimized using the fact that the character set size is small. For example sorting can be done faster, counting frequencies of items is faster and many interesting interview questions are based on this.
Basics
In Different Languages
- Strings in C
- String Class in C++
- String in Java
- Python String
- C# | String
- JavaScript String
- PHP | Strings
Basic Operations
- Length of a String
- Check for Same
- Search a Character
- Insert a Character
- Remove a Character
- Remove all occurrences
- Concatenating Two Strings
- Reverse a string
- Generate all Substrings
Easy Problems
- Check for Binary
- Camel Case Conversion
- Substrings with Corners as 1s
- Check for Panagram
- Check for Palindrome
- Check for Substring
- Check for Subsequence
- Check for Anagrams
- Check for K-Anagrams
- Longest Substring Between Equals
- Generate all binary strings from given pattern
- Smallest and Largest Word in a String
- Count number of equal pairs in a string
- All strings by placing spaces
- Char Frequencies in Order of Occurrence
- Char Frequencies in Alphabetical order
- URLify a given string
Medium Problems on String:
- First Repeating Character
- First Non-Repeating Character
- Check for Rotation
- K’th Non-repeating Character
- Implement atoi
- Add 2 Binary Strings
- Add n Binary Strings
- Multiply 2 Strings
- Divide large number
- Isomorphic Strings
- Remove Adjacent
- Roman to Integer
- Interleaved Strings
- Permutations of a String
- Longest Palindromic Substring
- Anagram substrings
- Binary strings without consecutive 1’s
- Lexicographically next string
- Split String into four distinct strings
- Word Break Problem
- Minimum Swaps for Bracket Balancing
- String to mobile numeric keypad sequence
- Minimum number from given sequence
- Shortest path to print a string on screen
Hard Problems on String:
- Lexicographic Rank of a String
- Multiply Large Numbers
- Ways to increase LCS length of 2 strings by one
- Min rotations required to get the same string
- Find if an array of strings can be chained to form a circle
- Alien Dictionary
- Make two strings Anagram
- Make two Strings Anagram Without Deletion
- Palindrome Substring Queries
- Powet Set in Lexicographic order
- Minimum Word Break
- Word Search - 8 Directions and Straight Movement
- Word Search - 4 Directions and Zig-Zag Allowed
- Minimum bracket reversals to make balanced
- Word Wrap problem
- Decode a string encoded with recursive substring counts
Please refer String Problems Topic Wise for the list of questions on different topics like binary string, subsequence and substring, pattern searching and palindrome.