Category Archives: Strings

Questions related to strings

Hamming Distance between two strings

You are given two strings of equal length, you have to find the Hamming Distance between these string. Where the Hamming distance between two strings of equal length is the number of positions at which the corresponding character are different. Examples: Input : str1[] = “geeksforgeeks”, str2[] = “geeksandgeeks” Output : 3 Explanation : The… Read More »

Implementation of Affine Cipher

The Affine cipher is a type of monoalphabetic substitution cipher, wherein each letter in an alphabet is mapped to its numeric equivalent, encrypted using a simple mathematical function, and converted back to a letter. The formula used means that each letter encrypts to one other letter, and back again, meaning the cipher is essentially a… Read More »

Boggle | Set 2 (Using Trie)

Given a dictionary, a method to do lookup in dictionary and a M x N board where every cell has one character. Find all possible words that can be formed by a sequence of adjacent characters. Note that we can move to any of 8 adjacent characters, but a word should not have multiple instances… Read More »

Check whether Strings are k distance apart or not

Given two strings, the task is to find if they are only less than or equal to k edit distance apart. It means that strings are only k edit distance apart when there are only k mismatches. Print Yes if there are less than or equal to k mismatches, Else No. Also print yes if… Read More »

Queries on subsequence of string

Given a string S and Q queries, each query contains a string T. The task is print “Yes” if T is subsequence of S, else print “No”. Examples: Input : S = “geeksforgeeks” Query 1: “gg” Query 2: “gro” Query 3: “gfg” Query 4: “orf” Output : Yes No Yes No For each query, using… Read More »

Queries for characters in a repeated string

Given a string X. Form a string S by repeating string X multiple times i.e appending string X multiple times with itself. There are Q queries of form i and j. The task is to print “Yes” if the element at index i is same as the element at index j in S else print… Read More »

Array of Strings in C++ (3 Different Ways to Create)

Array of Strings can be created in C++, which can be quite handy. There are 3 ways to create Array of Strings. Using 2D array (Both C and C++): This method is useful for shuffling, comparing and accessing characters randomly. Syntax: Char “Name” [“Number of Strings”][“MaxSize of String”] Example: Char colour [4][10] // Here 4… Read More »

Program to toggle all characters in a string

in a given string in which we toggle all characters. Examples: Input : gfg Output : GFG Input : aBc12# Output : AbC12# Input : tu@kmiNi Output : TU@KMInI Traverse the given string, if uppercase characters comes, convert into lowercase and lowercase latter convert into uppercase. Output: gEkF@RgEEK$ This article is contributed by MATHE_KA_BANDA. If… Read More »