Category Archives: Strings

Questions related to strings

Check if two strings are k-anagrams or not

Given two strings of lowercase alphabets and a value k, the task is to find if two strings are K-anagrams of each other or not. Two strings are called k-anagrams if following two conditions are true. Both have same number of characters. Two strings can become anagram by changing at most k characters in a… Read More »

Count of character pairs at same distance as in English alphabets

Given a string, the task is to count the number of pairs whose elements are at same distances as in the English alphabets. Note : Absolute distance between characters is considered. Examples: Input: str = “geeksforgeeks” Output: 4 Explanation: In this (g,s),(e,g),(e,k),(e,g) are the pairs that are at same distances as in English alphabets. Input:… Read More »

Print all palindromic partitions of a string

Given a string s, partition s such that every string of the partition is a palindrome. Return all possible palindrome partitioning of s. Example : Input : s = “bcc” Output : [[“b”, “c”, “c”], [“b”, “cc”]] Input : s = “geeks” Output : [[“g”, “e”, “e”, “k”, “s”], [“g”, “ee”, “k”, “s”]] We have… Read More »

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 »