Found 7197 Articles for C++

Count of N digit numbers not having given prefixes

Thanweera Nourin A V
Updated on 28-Jul-2023 15:20:37

146 Views

Here the problem is to determine the total number of strings of the length N containing characters '0' through '9' provided an integer N with an array of string prefixes pre[]. such that none of the strings can contain the provided prefixes. The aim of this article is to implement a program to find the count of N digit numbers not having given prefixes. A collection of various strings is referred to as an array in the C programming language because an array is a linear grouping of data pieces of a similar type. As we already know, the string ... Read More

Minimum addition/removal of characters to be done to make frequency of each character prime

Sakshi Koshta
Updated on 31-Jul-2023 13:29:57

190 Views

Optimising character frequency for primality is a challenging task in computer science that entails identifying the smallest number of character additions or removals required to make the frequency of each character in each string a prime integer. Cryptography, data reduction, and natural language processing are just a few of the applications for this issue. The frequency of characters in a string can be optimised for primality in this tutorial using a C++ method. We will start by involving further into the problem description and then propose an efficient solution. Method Dynamic programming Approach minOperations function Method Method ... Read More

Segregate 1s and 0s in separate halves of a Binary String

Shubham Vora
Updated on 28-Jul-2023 13:10:17

313 Views

In this tutorial, we need to separate all 1s and 0s of the given binary string in the two halves. Here, we need to take a substring from the given string and reverse it to separate 0s and 1s in different parts. Ultimately, we need to count the total number of reversals required for substring to separate 1s and 0s in two halves. Problem statement − We have given a binary string of even length. We need to take any substring from the given string multiple times and reverse it to separate it into two halves. We need to print ... Read More

Modify string by replacing all occurrences of given characters by specified replacing characters

Shubham Vora
Updated on 28-Jul-2023 13:07:54

249 Views

In this problem, we need to replace the characters of the given string according to the characters given in the array of pairs of characters. We will discuss two different approaches to solving the problem. In the first approach, we iterate through the characters of the given string and pairs of characters to replace each character. In the second approach, we will use an array of length 26 to store the replaced character related to each character and change the character of the given string. Problem statement − We have given a string str containing N lowercase alphabetic characters. Also, ... Read More

Minimum removals required such that a string can be rearranged to form a palindrome

Shubham Vora
Updated on 28-Jul-2023 13:06:05

1K+ Views

In this problem, we need to remove the minimum characters from the string and rearrange the remaining characters to make the string palindromic. To solve the problem, the first question we should ask ourselves is when we can make string palindromic. In below two cases, we can make string palindromic. If each character’s frequency is even in the given string. If only one character’s frequency is odd and all other characters' frequency is even. So, we need to remove minimum characters to make each character’s frequency even except for any single character. Problem statement − We have given ... Read More

Minimize removal of substring of 0s to remove all occurrences of 0s from a circular Binary String

Shubham Vora
Updated on 28-Jul-2023 13:04:06

148 Views

In this problem, we require to remove all zeros from the given binary string. Also, we require to remove pair of consecutive zeros at once and count the total number of pairs of zeros removal. We can solve the problem by counting the number of pairs of consecutive zeros in the given string. In this tutorial, we will learn two different solutions to solve the problem. Problem statement − We have given circular binary string str of length N. We need to find the minimum number of consecutive zeros required to remove all zeros from the string. Sample Examples Input ... Read More

Minimize flips required such that string does not any pair of consecutive 0s

Shubham Vora
Updated on 28-Jul-2023 12:58:09

209 Views

Here, we require to manipulate the binary string so that it doesn’t contain any consecutive zeros. If we find consecutive zeros, we need to change any zero to 1. So, we require to count the total number of 0 to 1 conversion we should make to remove all consecutive zeros from the string. Problem statement − We have given a binary string ‘str’ containing only 0 and 1. We require to find the minimum number of flips required so that the resultant string doesn’t contain any consecutive zeros. Sample Examples Input – 0101001 Output – 1 Explanation ... Read More

Longest Non-Increasing Subsequence in a Binary String

Shubham Vora
Updated on 28-Jul-2023 12:55:09

346 Views

In this problem, we require to find the longest non-increasing subsequence of the given string. The meaning of non-increasing is either character should be the same or in decreasing order. As binary string contains only ‘0’ and ‘1’, the resultant string should start with ‘1’ and end with ‘0’, or start and end with either ‘0’ or ‘1’. To solve the problem, we will count prefix ‘1’s and suffix ‘0’ at each position of the string and find the maximum sum of prefix ‘1’s and suffix ‘0’s. Problem statement − We have given binary string str. We need to ... Read More

Length of longest subset consisting of A 0s and B 1s from an array of strings

Shubham Vora
Updated on 28-Jul-2023 12:52:55

160 Views

In this problem, we need to find the longest subset containing at most A 0s and B1s. All we need to do is find all possible subsets using the array elements and find the longest subset containing maximum A 0s and B1. In this tutorial, first, we will learn the recursive approach to solve the problem. After that, we will optimize the code using the dynamic programming approach. Problem statement − We have given an array containing N binary strings. Also, we have given A and B integers. We need to make the longest subset using the given binary strings ... Read More

Construct a K-length binary string from an array based on given conditions

Shubham Vora
Updated on 28-Jul-2023 12:50:54

175 Views

In this tutorial, we require to construct a binary string of length K such that it should contain ‘1’ at the ith index if a subset-sum equal to I is possible using array elements. We will learn two approaches to solving the problem. In the first approach, we will use a dynamic programming approach to check whether the subset sum equal to index ‘I’ is possible. In the second approach, we will use a bitset to find all possible sums using array elements. Problem statement − We have given an array containing N integers. Also, we have given integer M ... Read More

Advertisements