Found 7346 Articles for C++

Maximum possible balanced binary substring splits with at most cost k

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

70 Views

The array in the C programming language has a fixed size, which means that once the size is specified, it cannot be changed; you can neither shrink it or extend it. As we know, an array is a group of identically data-typed elements kept in consecutive memory regions. Given an array of values v[] and a binary array a[]. The objective is to use as many k coins to divide the binary array as much as is possible while ensuring that each segment has an equal amount of 0s and 1s. i and j are the neighboring indices of the ... Read More

Decode a given string by removing duplicate occurrences

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

91 Views

The aim of this article is to implement a program to decode a given string by removing duplicate occurrences. As you are aware of what a string is, a string is nothing but a collection of characters. Also there is no restriction in the repetitions of characters in a string. A string can have the same character occurring multiple times. In this we will figure out a way to decode a given encoded string str by removing duplicate occurrences. The objective would be to decode the provided string str, which has been encoded with 'a' appearing just once, 'b' twice, ... Read More

Count of strings to be concatenated with a character having frequency greater than sum of others

Thanweera Nourin A V
Updated on 10-Aug-2023 15:45:40

48 Views

Our main aim here is to determine the most strings that are capable of being concatenated to ensure that just one letter has a frequency that exceeds the total of all the other characters, provided an array called arr[] containing M strings. Before going further, let's understand some basic concepts of array and string. The array is nothing but a group of identically data-typed elements held in consecutive memory sections. The array in the C programming language has a fixed size, which means that once the size is specified, it cannot be changed; you cannot shrink or extend it. Let's ... Read More

Count of N-length binary strings that are repeated concatenation of a substring

Thanweera Nourin A V
Updated on 28-Jul-2023 15:22:00

72 Views

The aim of this article is to implement a program to count of N-length binary strings that are repeated concatenation of a substring. The goal is to determine how many binary strings of the length N can be created by repeatedly concatenating a single substring of a given text, provided a positive integer called N. Problem Statement Implement a program to count of N-length binary strings that are repeated concatenation of a substring. Sample Example 1 Let us take the Input, N = 3 Output: 2 Explanation Listed below are the feasible binary string of length N=3 with ... Read More

Count of N digit numbers not having given prefixes

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

60 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

60 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

197 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

90 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

714 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

61 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

Advertisements