Category Archives: Strings

Questions related to strings

Remove a character from a string to make it a palindrome

Given a string, we need to check whether it is possible to make this string a palindrome after removing exactly one character from this. Examples: Input : str = “abcba” Output : Yes we can remove character ‘c’ to make string palindrome Input : str = “abcbea” Output : Yes we can remove character ‘e’… Read More »

Sort a string according to the order defined by another string

Given two strings (of lowercase letters), a pattern and a string. The task is to sort string according to the order defined by pattern. It may be assumed that pattern has all characters of the string and all characters in pattern appear only once. Examples: Input : pat = “bca”, str = “abc” Output :… Read More »

Smallest Palindrome after replacement

Given a string which has some lowercase alphabet characters and one special character dot(.). We need to replace all dots with some alphabet character in such a way that resultant string becomes a palindrome, in case of many possible replacements, we need to choose palindrome string which is lexicographically smallest. If it is not possible… Read More »

XOR Cipher

XOR Encryption is an encryption method used to encrypt data and is hard to crack by brute-force method, i.e generating random encryption keys to match with the correct one. Below is a simple implementation in C++. The concept of implementation is to first define a XOR – encryption key and then to perform XOR operation… Read More »

Perfect reversible string

You are given a string ‘str’, the task is to check that reverses of all possible substrings of ‘str’ are present in ‘str’ or not. Input : str = “ab” Output: “NO” // all substrings are “a”,”b”,”ab” but reverse // of “ab” is not present in str Input : str = “aba” Output: “YES” Input… Read More »

String with additive sequence

Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. A valid string should contain at least three digit to make one additive sequence.… Read More »