String in Data Structure
Last Updated :
09 Nov, 2024
Improve
A string is a sequence of characters. The following facts make string an interesting data structure.
- Small set of elements. Unlike normal array where we can have larger values, 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#. In C++, strings are mutable and other languages also provide mechanisms to support mutable strings.
- 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 other interesting interview questions are based on this.
Basics of Strings:
String in different language:
- Strings in C and Storage for Strings in C
- String Class in C++
- String in Java
- Python String
- C# | String
- JavaScript String
- PHP | Strings
Basic Operations of String:
- Length of a String
- Check if two strings are same
- Search a Character
- Insert a Character at a Position
- Remove a Character at a Position
- Insert a character at Multiple Positions
- Remove all occurrences of a character
- Concatenating Two Strings
- Reverse a string
- Generate all Substrings of a String
Please refer String Problems Topic Wise for the list of questions on different topics like binary string, subsequence and substring, pattern searching and palindrome.
Easy Problems on String:
- Check for Binary
- Camel Case Conversion
- Binary Substrings with Corners as 1s
- Check for Panagram
- Check for Palindrome
- Check for Substring
- Check for Subsequence
- Check for Anagrams
- Duplicates in a String
- Longest Substring Between Equals
- Left and Right Rotate
- Check for Rotation
- Validate an IP address
- Count strings with consecutive 1’s
- Generate all binary strings from given pattern
- Add n binary strings
- Divide large number represented as string
- Smallest and Largest Word in a String
- Count number of equal pairs in a string
- Second most repeated word in a sequence
- Print all possible strings that can be made by placing spaces
- Left Rotation and Right Rotation of a String
- Sort string of characters
- Character Frequencies in Order of Occurrence
- Character Frequencies in Alphabetical order
Medium Problems on String:
- First Repeating Character
- First Non-Repeating Character
- K’th Non-repeating Character
- Implement atoi
- Multiply 2 Strings
- Isomorphic Strings
- Remove Adjacent
- Roman to Integer
- Interleaved Strings
- Permutations of a String
- Longest Palindromic Substring
- Queries for characters in a repeated string
- Count anagram substrings
- Count binary strings without consecutive 1’s
- Lexicographically next string
- Check if given string can be split into four distinct strings
- Word Break Problem
- Length of Longest Balanced Subsequence
- Minimum Swaps for Bracket Balancing
- Convert a sentence into its equivalent mobile numeric keypad sequence
- Form minimum number from given sequence
- Print shortest path to print a string on screen
- Mirror characters of a string
Hard Problems on String:
- Lexicographic Rank of a String
- Multiply Large Numbers represented as Strings
- Count ways to increase LCS length of two 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 number of bracket reversals needed to make an expression balanced
- Word Wrap problem ( Space optimized solution )
- Decode a string recursively encoded as count followed by substring


