String Data Structure
Practice Problems on String
Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character ‘\0’.
Declaring a string is as simple as declaring a one dimensional array. Below is the basic syntax for declaring a string in C programming language.
char str_name[size];
‘Recent Articles’ on Strings
Topics :
- Function to copy string
- Pangram Checking
- Missing characters to make a string Pangram
- Check if a string is Pangrammatic Lipogram
- Removing punctuations from a given string
- Rearrange characters in a string such that no two adjacent are same
- Program to check if input is an integer or a string
- Quick way to check if all the characters of a string are same
- Program to find the initials of a name
- Check Whether a number is Duck Number or not
- Round the given number to nearest multiple of 10
- Change string to a new character set
- Find one extra character in a string
- Array of Strings in C++ (3 Different Ways to Create)
- Strings in C
- Storage for Strings in C
- sprintf() in C
- C program to find second most frequent character
- C Program to Sort an array of names or strings
- C++ Program to remove spaces from a string
- String Class in C++
- C++ program to concatenate a string given number of times
- std::string::append vs std::string::push_back() vs Operator += in C++
- Comparing two strings in C++
- Convert string to char array in C++
- Extract all integers from string in C++
- std::regex_match, std::regex_replace() | Regex (Regular Expression) In C++
- C program to Replace a word in a text by another given word
- stringstream in C++ and its applications
- C++ string class and its applications
- String Class in Java
- String in Switch Case in Java
- Java program to swap first and last characters of words in a sentence
- Java program to expand a String if range is given?
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- Get the first letter of each word in a string using regex in Java
- Reverse words in a given String in Java
- Reverse a string in Java (5 Different Ways)
- Compare two strings lexicographically in Java
- Searching characters and substring in a String in Java
- Possible Words using given characters in Python
- Using Set() in Python Pangram Checking
- Using OrderedDict() in Python to check order of characters in string
- Print anagrams together in Python using List and Dictionary
- K’th Non-repeating Character in Python using List Comprehension and OrderedDict
- Prefix matching in Python using pytrie module
- Print number with commas as 1000 separators in Python
- Pattern Occurrences : Stack Implementation Java
- String Methods in Python : Set 1 , Set 2 , Set 3
- Dictionary and counter in Python to find winner of election
- Maximum length of consecutive 1’s in a binary string in Python using Map function
- Python code to print common characters of two Strings in alphabetical order
- Using Counter() in Python to find minimum character removal to make two strings anagram
- Reverse string in Python
- Python groupby method to remove all consecutive duplicates
- Generate two output strings depending upon occurrence of character in input string in Python
- Python Dictionary to find mirror characters in a string
- Python | Convert a list of characters into a string
- Map function and Lambda expression in Python to replace characters
- Zip function in Python to change to a new character set
- SequenceMatcher in Python for Longest Common Substring
- Python | Print the initials of a name with last name in full
- Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
- Python program to count number of vowels using sets in given string
- Python set to check if string is panagram
- Python | Check if a Substring is Present in a Given String
- Python sorted() to check if two strings are anagram or not
- Python | Remove leading zeros from an IP address
- Python | Count all prefixes in given string with greatest frequency
- Check if both halves of the string have same set of characters in Python
- Concatenated string with uncommon characters in Python
- Second most repeated word in a sequence in Python
- Regex in Python to put spaces between words starting with capital letters
- Python code to move spaces to front of string in single traversal
- String slicing in Python to rotate a string
- String slicing in Python to check if a string can become empty by recursive deletion
- Reverse words in a given String in Python
- Run Length Encoding in Python
- Anagram checking in Python using collections.Counter()
- Remove all duplicates from a given string in Python
- Remove all consecutive duplicates from the string
- Python program to check if a string is palindrome or not
Arthimetic Operation in String :
- Smallest number with sum of digits as N and divisible by 10^N
- Minimum sum of squares of character counts in a given string after removing k characters
- Maximum and minimum sums from two numbers with digit replacements
- Check if a given string is sum-string
- Sum of two large numbers
- Calculate sum of all numbers present in a string
- Extract maximum numeric value from a given string
- Calculate maximum value using ‘+’ or ‘*’ sign between two numbers in a string
- Maximum segment value after putting k breakpoints in a number
- Difference of two large numbers
- Check if a large number is divisible by 4 or not
- Check if a large number is divisible by 11 or not
- Number of substrings divisible by 6 in a string of integers
- Decimal representation of given binary string is divisible by 5 or not
- Number of substrings divisible by 8 but not by 3
- To check divisibility of any large number by 999
- Multiply Large Numbers represented as Strings
- Divide large number represented as string
- Remainder with 7 for large numbers
- Given two numbers as strings, find if one is a power of other
- Check whether a given number is even or odd
- Product of nodes at k-th level in a tree represented as string
- Program to find remainder when large number is divided by 11
- Ways to remove one element from a binary string so that XOR becomes zero
- Find the maximum subarray XOR in a given array
- Calculate the difficulty of a sentence
- Minimum Index Sum for Common Elements of Two Lists
Character Counting Based Problems :
- Count Uppercase, Lowercase, special character and numeric values
- Find the smallest window in a string containing all characters of another string
- Smallest window that contains all characters of string itself
- Count number of substrings with exactly k distinct characters
- Number of substrings with count of each character as k
- String with k distinct characters and no same characters adjacent
- Number of substrings of a string
- Distinct strings with odd and even changes allowed
- Find k’th character of decrypted string
- Count characters at same position as in English alphabets
- Count words in a given string
- Count words present in a string
- Count of words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of given word
- Program to find Smallest and Largest Word in a String
- Count substrings with same first and last characters
- Recursive solution to count substrings with same first and last characters
- Count of distinct substrings of a string using Suffix Array
- Count of distinct substrings of a string using Suffix Trie
- Count number of strings (made of R, G and B) using given combination
- Count of strings that can be formed using a, b and c under given constraints
- Count of substrings of a binary string containing K ones
- Group words with same set of characters
- Print all distinct characters of a string in order (3 Methods)
- Print common characters of two Strings in alphabetical order
- Common characters in n strings
- Find uncommon characters of the two strings
- Concatenated string with uncommon characters of two strings
- Program to remove vowels from a String
- Remove consecutive vowels from string
- Program to count vowels in a string (Iterative and Recursive)
- Count consonants in a string (Iterative and recursive methods)
- Alternate vowel and consonant string
- Given a binary string, count number of substrings that start and end with 1
- Number of distinct permutation a String can have
- Time complexity of all permutations of a string
- Permutations of a given string using STL
- Check if both halves of the string have same set of characters
- Count words that appear exactly two times in an array of words
- Check if frequency of all characters can become same by one removal
- Check if a string has all characters with same frequency with one variation allowed
- Count ways to increase LCS length of two strings by one
- Find the character in first string that is present at minimum index in second string
- Remove characters from the first string which are present in the second string
- Length of Longest sub-string that can be removed
- Count of character pairs at same distance as in English alphabets
- Count number of equal pairs in a string
- Count of strings where adjacent characters are of difference one
- Print number of words, vowels and frequency of each character
- Longest subsequence where every character appears at-least k times
- Given two strings, find if first string is a subsequence of second
- Number of subsequences of the form a^i b^j c^k
- Number of subsequences in a string divisible by n
- Find number of times a string occurs as a subsequence in given string
- Number of subsequences as “ab” in a string repeated K times
- Count of ‘GFG’ Subsequences in the given string
- Count Distinct Subsequences
- Count distinct occurrences as a subsequence
- Longest common subsequence with permutations allowed
- Repeated subsequence of length 2 or more
- Print all longest common sub-sequences in lexicographical order
- Printing Longest Common Subsequence | Set 2
- Given number as string, find number of contiguous subsequences which recursively add up to 9 | Set 2
- Shortest Uncommon Subsequence
- Shortest Superstring Problem
- Printing Shortest Common Supersequence
- Shortest possible combination of two strings
- A Space Optimized Solution of LCS
- Sort a string according to the order defined by another string
- Shortest Common Supersequence
- Longest Repeating Subsequence
- Find largest word in dictionary by deleting some characters of given string
- Dynamic Programming | Set 12 (Longest Palindromic Subsequence)
- Perfect reversible string
- Reversing an Equation
- Left Rotation and Right Rotation of a String
- Generate all rotations of a given string
- Minimum rotations required to get the same string
- Check if strings are rotations of each other or not
- Check if a string can be obtained by rotating another string 2 places
- Count rotations divisible by 4
- Check if all rows of a matrix are circular rotations of each other
- Print reverse of a string using recursion
- Print words of a string in reverse order
- Program to reverse a string (Iterative and Recursive)
- Write a program to reverse an array or string
- Reverse an array without affecting special characters
- Reverse words in a given string
- Reverse individual words
- Reverse a string preserving space positions
- Reverse string without using any temporary variable
- Print reverse string after removing vowels
- Reverse vowels in a given string
- Reverse String according to the number of words
- Reverse each word in a linked list node
- Find if an array of strings can be chained to form a circle
- Sort an array of strings according to string lengths
- Sorting array of strings (or words) using Trie
- Sort string of characters
- Alternate Lower Upper String Sort
- Program to sort string in descending order
- Print array of strings in sorted order without copying one string into another
- Sort the given string using character search
- Given a sorted dictionary of an alien language, find order of characters
- Rearrange a string in sorted order followed by the integer sum
- Print distinct sorted permutations with duplicates allowed in input
- Minimum cost to sort strings using reversal operations of different costs
- Print number in ascending order which contains 1, 2 and 3 in their digits.
- Search in an array of strings where non-empty strings are sorted
- Sparse Search
- Lower case to upper case – An interesting fact
- isupper() and islower() and their application in C++
- Case conversion (Lower to Upper and Vice Versa) of a string using BitWise operators in C/C++
- Maximum distinct lowercase alphabets between two uppercase
- First uppercase letter in a string (Iterative and Recursive)
- Convert characters of a string to opposite case
- gOOGLE cASE of a given sentence
- Print all words matching a pattern in CamelCase Notation Dictonary
- Camel case of a given sentence
- Permute a string by changing case
- Toggle case of a string using Bitwise Operators
- How to design a tiny URL or URL shortener?
- Given a string, find its first non-repeating character
- Print all permutations with repetition of characters
- Find the first non-repeating character from a stream of characters
- Convert to a string that is repetition of a substring of k length
- Smallest length string with repeated replacement of two distinct adjacent
- Distributing all balls without repetition
- Maximum consecutive repeating character in string
- Minimum number of deletions so that no two consecutive are same
- K’th Non-repeating Character
- Find repeated character present first in a string
- Find the first repeated word in a string
- Find the first repeated character in a string
- Second most repeated word in a sequence
- Most frequent word in an array of strings
- Efficiently find first repeated character in a string without using any additional data structure in one traversal
- Queries for characters in a repeated string
- Return maximum occurring character in an input string
- Generate two output strings depending upon occurrence of character in input string.
- Print characters and their frequencies in order of occurrence
- Program to count occurrence of a given character in a string
- Check if all occurrences of a character appear together
- Group all occurrences of characters according to first appearance
- Print the string by ignoring alternate occurrences of any character
- Print the string after the specified character has occurred given no. of times
- Find all occurrences of a given word in a matrix
- Replace all occurrences of string AB with C without using extra space
- Rearrange a binary string as alternate x and y occurrences
- Remove recurring digits in a given number
- Find the most frequent digit without using array/string
- Remove spaces from a given string
- Move spaces to front of string in single traversal
- Put spaces between words starting with capital letters
- Removing spaces from a string using Stringstream
- Remove extra spaces from a string
- URLify a given string (Replace spaces is %20)
- String containing first letter of every word in a given string with spaces
- Print all possible strings that can be made by placing spaces
- Print all possible strings that can be made by placing spaces
- Check whether two strings are anagram of each other
- Given a sequence of words, print all anagrams together | Set 2
- Anagram Substring Search
- Print all pairs of anagrams in a given array of strings
- Remove minimum number of characters so that two strings become anagram
- Check if two strings are k-anagrams or not
- Check if binary representations of two numbers are anagram
- Given a sequence of words, print all anagrams together using STL
- Check if all levels of two trees are anagrams or not
- Count of total anagram substrings
- Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character
- C Program to Check if a Given String is Palindrome
- Check if a given string is a rotation of a palindrome
- C++ Program to print all palindromes in a given range
- Check if characters of a given string can be rearranged to form a palindrome
- Dynamic Programming | Set 28 (Minimum insertions to form a palindrome)
- Longest Palindromic Substring | Set 2
- Find all palindromic sub-strings of a given string
- Online algorithm for checking palindrome in a stream
- Given a string, print all possible palindromic partitions
- Print all palindromic partitions of a string
- Dynamic Programming | Set 17 (Palindrome Partitioning)
- Count All Palindromic Subsequence in a given String
- Minimum characters to be added at front to make string palindrome
- Palindrome Substring Queries
- Suffix Tree Application 6 – Longest Palindromic Substring
- Palindrome pair in an array of words (or strings)
- Make largest palindrome by changing at most K-digits
- Lexicographically first palindromic string
- Recursive function to check if a string is palindrome
- Minimum number of Appends needed to make a string palindrome
- Longest Non-palindromic substring
- Minimum number of deletions to make a string palindrome
- Minimum steps to delete a string after repeated deletion of palindrome substrings
- Count of Palindromic substrings in an Index range
- Minimum insertions to form a palindrome with permutations allowed
- Nth Even length Palindrome
- Count of operations to make a binary string”ab” free
- Change if all bits can be made same by single flip
- Length of Longest sub-string that can be removed
- Number of flips to make binary string alternate
- 1’s and 2’s complement of a Binary Number
- Efficient method for 2’s complement of a binary string
- Count binary strings with k times appearing adjacent two set bits
- Count strings with consecutive 1’s
- Generate all binary strings from given pattern
- Add two bit strings
- Count number of binary strings without consecutive 1’s
- Generate all binary permutations such that there are more or equal 1’s than 0’s before every point in all permutations
- Check if a string follows a^nb^n pattern or not
- Binary representation of next number
- Binary representation of next greater number with same number of 1’s and 0’s
- Maximum difference of zeros and ones in binary string
- Check if a binary string has a 0 between 1s or not | Set 2
- Min flips of continuous characters to make all characters same in a string
- Concatenation of two strings in PHP
- Program to add two binary strings
- Convert String into Binary Sequence
- Generate all binary strings without consecutive 1’s
- Minimum number of characters to be removed to make a binary string alternate
- Check divisibility of binary string by 2^k
- Removing elements between the two zeros
- Find i’th Index character in a binary string obtained after n iterations
- Number of substrings with odd decimal value in a binary string
- Generate n-bit Gray Codes
- Print N-bit binary numbers having more 1’s than 0’s in all prefixes
- Add n binary strings
- Powet Set in Lexicographic order
- Lexicographically n-th permutation of string
- Lexicographic rank of string using stl
- Lexicographically minimum string rotation | Set 1
- Generating distinct subsequences of a given string in lexicographic order
- Lexicographically smallest string obtained after concatenating array
- Lexicographical Maximum substring of string
- Lexicographical concatenation of all substrings of a string
- Construct lexicographically smallest palindrome
- Lexicographically smallest string whose hamming distance from given string is exactly K
- Lexicographically next string
- Lexicographically largest subsequence such that every character occurs at least k times
- Lexicographically first alternate vowel and consonant string
- Find a string in lexicographic order which is in between given two strings
- Print all permutations in sorted (lexicographic) order
- How to find Lexicographically previous permutation?
- Find n-th lexicographically permutation of a string | Set 2
- Lexicographic rank of a string
- Searching for Patterns | Set 5 (Finite Automata)
- Pattern Searching | Set 7 (Boyer Moore Algorithm – Bad Character Heuristic)
- Manacher’s Algorithm – Linear Time Longest Palindromic Substring – Part 4
- Z algorithm
- Search a Word in a 2D Grid of characters
- Printing string in plus ‘+’ pattern in the matrix
- Wildcard Pattern Matching
- Dynamic Programming | Wildcard Pattern Matching | Linear Time and Constant Space
- Replace a character c1 with c2 and c2 with c1 in a string S
- Aho-Corasick Algorithm
- Count of occurrences of a “1(0+)1” pattern in a string
- Find all the patterns of “1(0+)1” in a given string | SET 2
- In-place replace multiple occurrences of a pattern
- Find all strings that match specific pattern in a dictionary
- Check if string follows order of characters defined by a pattern or not
- Find nth term of the Dragon Curve Sequence
- Count of number of given string in 2D character array
- Tokenizing a string in C++
- Split a sentence into words in C++
- How to split a string in C/C++, Python and Java?
- Check if given string can be split into four distinct strings
- Split numeric, alphabetic and special symbols from a String
- Splitting a Numeric String
- Ways to split string such that each partition starts with distinct character
- Partition a number into two divisble parts
- Partition given string in such manner that i’th substring is sum of (i-1)’th and (i-2)’th substring
- Breaking a number such that first part is integral division of second by a power of 10
- Divide a string in N equal parts
- Minimum Word Break
- Word Break Problem
- Word Break Problem using Backtracking
Balance Parentheses & Bracket Evaluation :
- Identify and mark unmatched parenthesis in an expression
- Cost to Balance the parentheses
- Check for balanced parentheses in an expression | O(1) space
- Check for balanced parentheses in an expression
- Length of Longest Balanced Subsequence
- Balanced expression with replacement
- Evaluate a boolean expression represented as string
- Find maximum depth of nested parenthesis in a string
- Print all ways to break a string in bracket form
- Find an equal point in a string of brackets
- Minimum Swaps for Bracket Balancing
- Check if two expressions with brackets are same
- Expression contains redundant bracket or not
- Range Queries for Longest Correct Bracket Subsequence
- Evaluate an array expression with numbers, + and –
- Print Bracket Number
- Find index of closing bracket for a given opening bracket in an expression
- Binary tree to string with brackets
- Construct Binary Tree from String with bracket representation
- Minimum number of bracket reversals needed to make an expression balanced
- Convert all substrings of length ‘k’ from base ‘b’ to decimal
- Convert Binary fraction to Decimal
- Convert decimal fraction to binary number
- Convert a sentence into its equivalent mobile numeric keypad sequence
- Check if it is possible to convert one string into another with given constraints
- Converting one string to other using append and delete last operations
- Converting Decimal Number lying between 1 to 3999 to Roman Numerals
- Converting Roman Numerals to Decimal lying between 1 to 3999
- Inverting the Move to Front Transform
- Burrows – Wheeler Data Transform Algorithm
- Check if it is possible to transform one string to another
- Transform the string
- An in-place algorithm for String Transformation
- Ways of transforming one string to other by removing 0 or more characters
- Transform One String to Another using Minimum Number of Given Operation
- Convert Ternary Expression to a Binary Tree
- Prefix to Infix Conversion
- Prefix to Postfix Conversion
- Postfix to Prefix Conversion
- Postfix to Infix
- Word Wrap problem ( Space optimized solution )
- Form minimum number from given sequence
- Maximum number of characters between any two same character in a string
- Print shortest path to print a string on screen
- Minimum number of stops from given path
- Check whether second string can be formed from characters of first string
- Mirror characters of a string
- Find words which are greater than given length k
- Find last index of a character in a string
- Find position of the given number among the numbers made of 4 and 7
- Find winner of an election where votes are represented as candidate names
- Compare Version Numbers with large inputs allowed
- Possibility of moving out of maze
- Possibility of a word from a given set of characters
- Find the arrangement of queue at given time
- Program to generate all possible valid IP addresses from given string
- Program to validate an IP address
- Program to check for a Valid IMEI Number
- Decode a median string to the original string
- Decode a string recursively encoded as count followed by substring
- Minimal operations to make a number magical
- Program to check for ISBN
- Program for credit card number validation
- Maximize a number considering permutations with values smaller than limit
- Find if a string starts and ends with another given string
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.