Found 7346 Articles for C++

Count of N length Strings having S as a Subsequence

Prabhdeep Singh
Updated on 24-Aug-2023 14:15:40

84 Views

We are given a string of length S and given an another number n which represents the length of the strings which might contains S as the subsequence. We have to find the number of unique strings of length N which contains S as the subsequence, where a subsequence is the set of characters from the given string which may be all the characters or not and they not need to be continuous. Sample Examples Input string str = "xyz" int n = 3 Output 1 Explanation There is only one string of length 3 that contains the ... Read More

Count of Subsequences of given string X in between strings Y and Z

Prabhdeep Singh
Updated on 24-Aug-2023 14:13:15

76 Views

A subsequence is a string that can be achieved from another string by removing some (possibly none or all) from a given string that may not be continuous. We are given a string and have to find the number of subsequences that are greater than equal to the given string Y and less than equal to another given string Z. We will use dynamic programming to solve the problem as brute force will take exponential time. Brute Force Approach The brute forces approach is to find all the subsequences of the given string X and then check if they are ... Read More

Longest Substring with at most X 0s and Y 1s of given String

Prabhdeep Singh
Updated on 24-Aug-2023 14:11:39

141 Views

A substring is the continuous sequence of the character from the given string which can be achieved by removing some character from the front and the end of the substring (possibly all or none). We are given a binary string and we have to find the length of the longest substring that contains at most X number zeros and Y number of ones where X and Y are given inputs. Sample Examples Input  string str = "101011"; int x = 1; int y = 2; Output The length of the longest substring with at most X zeroes and ... Read More

XOR of all substrings of a given Binary String

Prabhdeep Singh
Updated on 24-Aug-2023 14:09:57

171 Views

A binary string is a string that contains only two different types of characters in it which are '0' and '1'. Substrings are strings that are formed by deleting some character from the given string from the beginning and from the ending (possibly zero or all). We are given a string and we have to get all the substrings of it and take XOR of it. XOR is a bitwise operator that gives the result − if both the bits are the same then it will return zero otherwise 1. Input  string str = "10101" Output  XOR of all ... Read More

Minimum cost to delete characters from String A to remove any subsequence as String B

Prabhdeep Singh
Updated on 24-Aug-2023 14:02:39

130 Views

We are given two strings string A and string B along with an array that represents the cost to delete the ith character of the given string A. We need to delete some characters of string A (possibly zero or none) with the minimum cost such that no subsequence of A represents string B. We are going to see three approaches to implementing the code that is the recursive approach; the recursive and memoization approach; and tabulation or iterative dp. Example Let's have a look at the following example − Input string a = "xanxd" string b = ... Read More

Transform string A into B by deleting characters from ends and reinserting at any position

Prabhdeep Singh
Updated on 24-Aug-2023 13:56:43

50 Views

Anagram of a string means a string contains exact same characters as another string with the order of characters may vary from the original string, so we called that both strings are anagram of each other. Here we have given the two strings first and second which are anagrams of each other. And our task is to minimize the count of operations to make the first string as second string. An operation is that we can delete an character from the begin or end of an first string and reinserting at any position. Sample Example Input  First: "hello", Second: "ohlle" ... Read More

Count of possible distinct Binary strings after replacing 11 with 0

Prabhdeep Singh
Updated on 24-Aug-2023 13:54:22

53 Views

A binary string is a string that contains only two types of different characters zeroes and ones. We can replace a substring '11' of the given string with another string '0' and we have to find the number of different possible strings we can get from it. We are going to use dynamic programming to get the solution as other methods may take exponential time complexity. Sample Example Input string str = 11010 Output 2 Explanation We can replace the first two numbers with the zero and can get another string 0010 and the second string is the ... Read More

Permutations and Combinations (Concept, Examples, C++ Program)

Eva Sharma
Updated on 24-Aug-2023 18:27:49

409 Views

Permutations and Combinations refer to the arrangements of objects in mathematics. Permutation − In permutation, the order matters. Hence, the arrangement of the objects in a particular order is called a permutation. Permutations are of two types − Permutation with repetition Suppose we have to make a three-digit code. Some possible numbers are 123, 897, 557, 333, 000, and 001. So how many numbers can we make like this? Let us look at it this way− In the once place, we have ten options − 0-9 Similarly, at the tenth and the hundredth place also, we have ten options. 0-9. ... Read More

HCF of an array of fractions (or rational numbers)

Eva Sharma
Updated on 24-Aug-2023 18:26:00

225 Views

HCF or the Highest common factor of two or more numbers refers to the highest number which divides them. A rational number is the quotient p/q of two numbers such that q is not equal to 0. Problem Statement Given an array with fractional numbers, find the HCF of the numbers. Example 1 Input [{4, 5}, {10, 12}, {24, 16}, {22, 13}] Output {2, 3120} Explanation The fractional numbers given are: 4/5, 10/12, 24/16 and 22/13 2/3120 is the largest number that divides all of them. Example 2 Input [{18, 20}, {15, 12}, {27, 12}, {20, 6}] ... Read More

Check for Amicable Pair

Thanweera Nourin A V
Updated on 23-Aug-2023 21:53:26

2K+ Views

The concept of an amicable pair of numbers or a friendly pair of numbers seems interesting right? So what exactly are amicable pairs of numbers? Two numbers are said to be an amicable pair of numbers only if the sum of the first number's proper divisors equals the sum of the second number's proper divisors. Also just in case you had forgotten, The Pythagoreans were always known for associating numbers with characteristics like justice and friendship. Problem Statement Implement a program to check whether the given pair of numbers is an amicable pair or not. ... Read More

Advertisements