Questions related to strings

## Longest Common Subsequence | DP-4

We have discussed Overlapping Subproblems and Optimal Substructure properties in Set 1 and Set 2 respectively. We also discussed one example problem in Set 3.… Read More »

## KMP Algorithm for Pattern Searching

Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] in txt[]. You may… Read More »

## Naive algorithm for Pattern Searching

Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] in txt[]. You may… Read More »

## Find the smallest window in a string containing all characters of another string

Given two strings string1 and string2, the task is to find the smallest substring in string1 containing all characters of string2 efficiently. Examples: Input: string… Read More »

## Run Length Encoding

Given an input string, write a function that returns the Run Length Encoded string for the input string. For example, if the input string is… Read More »

## Reverse words in a given string

Example: Let the input string be “i like this program very much”. The function should change the string to “much very program this like i”… Read More »

## Check for balanced parentheses in an expression

Given an expression string exp , write a program to examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp. Example: Input:… Read More »

## Print list items containing all characters of a given word

There is a list of items. Given a specific word, e.g., “sun”, print out all the items in list which contain all the characters of… Read More »

## Write a program to reverse an array or string

Given an array (or string), the task is to reverse the array/string. Examples : Input : arr[] = {1, 2, 3} Output : arr[] =… Read More »

## Given a string, find its first non-repeating character

Given a string, find the first non-repeating character in it. For example, if the input string is “GeeksforGeeks”, then output should be ‘f’ and if… Read More »

## Divide a string in N equal parts

Difficulty Level: Rookie Question: Write a program to print N equal parts of a given string. Solution: 1) Get the size of the string using… Read More »

## Write a program to print all permutations of a given string

A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with… Read More »

## Print reverse of a string using recursion

Write a recursive function to print reverse of a given string. Program: C++ filter_none edit close play_arrow link brightness_4 code // C++ program to reverse… Read More »

## A Program to check if strings are rotations of each other or not

Given a string s1 and a string s2, write a snippet to say whether s2 is a rotation of s1? (eg given s1 = ABCD… Read More »

## Remove characters from the first string which are present in the second string

Write an efficient C function that takes two strings as arguments and removes the characters from first string which are present in second string (mask… Read More »