Category Archives: Strings

Questions related to strings

Word Break Problem using Backtracking

Given a valid sentence without any spaces between the words and a dictionary of valid English words, find all possible ways to break the sentence in individual dictionary words. Example Consider the following dictionary { i, like, sam, sung, samsung, mobile, ice, cream, icecream, man, go, mango} Input: “ilikesamsungmobile” Output: i like sam sung mobile… Read More »

Nth character in Concatenated Decimal String

If all decimal numbers are concatenated in a string then we will get a string which looks like string P as shown below. We need to tell Nth character of this string. P = “12345678910111213141516171819202122232425262728293031….” Examples: N = 10 10th character is 1 N = 11 11th character is 0 N = 50 50th character… Read More »

Count All Palindrome Sub-Strings in a String

Given a string, the task is to count all palindrome substring in a given string. Length of palindrome substring is greater then or equal to 2. Examples: Input : str = “abaab” Output: 3 Explanation : All palindrome substring are : “aba” , “aa” , “baab” Input : str = “abbaeae” Output: 4 Explanation :… Read More »

Group all occurrences of characters according to first appearance

Given a string of lowercase characters, the task is to print the string in a manner such that a character comes first in string displays first with all its occurrences in string. Examples: Input : str = “geeksforgeeks” Output: ggeeeekkssfor Explanation: In the given string ‘g’ comes first and occurs 2 times so it is… Read More »

Count characters at same position as in English alphabets

Given a string of lower and uppercase characters, the task is to find that how many characters are at same position as in English alphabets. Examples: Input: ABcED Output : 3 First three characters are at same position as in English alphabets. Input: geeksforgeeks Output : 1 Only ‘f’ is at same position as in… Read More »

Distinct strings with odd and even changes allowed

Given an array of lower case strings, the task is to find the number of strings that are distinct. Two strings are distinct if on applying the following operations on one string the second string cannot be formed. A character on odd index can be swapped with another character at odd index only. A character… Read More »