Found 7346 Articles for C++

C++ Program to find minimum moves to get all books contiguous

Arnab Chakraborty
Updated on 08-Apr-2022 08:05:48

188 Views

Suppose we have an array A with n elements. Consider there is a bookshelf and this =can fit n books. The i-th position of bookshelf is A[i], is 1 if there is a book on this position and 0 otherwise. There will be at least one book in the bookshelf. In one move, we can take some contiguous segment [l to r] and −Shift them to the right by 1. This move can be done only if there are empty slots at the right side of r.Shift them to the left by 1: This move can be done only if ... Read More

C++ Program to count operations to make filename valid

Arnab Chakraborty
Updated on 08-Apr-2022 08:02:13

113 Views

Suppose we have a string S with n letters. Amal is trying to send a file in the social network, but there is an unexpected problem. If the name of the file contains three or more "x" consecutively, the system considers that the file content does not correspond to the social network. We have the filename in S. We have to check whether the minimum number of characters to be removed S so that, the name does not contain "xxx" as a substring.Problem CategoryTo solve this problem, we need to manipulate strings. Strings in a programming language are a stream ... Read More

C++ Program to find minimum k for candy distribution

Arnab Chakraborty
Updated on 08-Apr-2022 07:58:31

261 Views

Suppose we have an array A with n elements. Amal has n friends, the i-th of his friends has A[i] number of candies. Amal's friends do not like when they have different numbers of candies. So Amal performs the following set of actions exactly once −Amal chooses k (0 ≤ k ≤n) arbitrary friendsAmal distributes their A[i1] + A[i2] + ... + A[ik] candies among all n friends. During distribution for each of A[i1] + A[i2] + ... + A[ik] candies he chooses new owner. That can be any of n friends. (Any candy can be given to the person, ... Read More

C++ Program to find opponent in a circular standing of persons

Arnab Chakraborty
Updated on 08-Apr-2022 07:54:41

89 Views

Suppose we have three numbers a, b and c. There are k numbers of students (k is even) standing on a circle, they are numbered from 1 to k in clockwise order. We do not know the value of k. Each person is watching through the center of the circle and can see the opponent who is standing at the other side of the circle. The person with the number 'a' is looking at the person with the number 'b'. We have to find, which person is at the opposite side of the person with number 'c'. If we cannot ... Read More

C++ Program to get length of longest subsequence in n times copied sequence

Arnab Chakraborty
Updated on 08-Apr-2022 07:50:45

130 Views

Suppose we have an array A with n elements. We can make another array consisting of n copies of the old array, added elements back-to-back. We have to find the the length of the new array's longest increasing subsequence? We know that a sequence p is a subsequence of an array b if p can be obtained from b by removing zero or more elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.Problem CategoryAn array in the data structure is a finite collection of elements of a ... Read More

C++ Program to count ordinary numbers in range 1 to n

Arnab Chakraborty
Updated on 08-Apr-2022 07:47:40

550 Views

Suppose we have a number n. A number is a positive integer n, and that said to be an ordinary number if in the decimal notation all its digits are the same. We have to count the number of ordinary numbers in range 1 to n.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first and to do that we have to study the particular problem in detail. A recursive approach can be used if there is a recurring appearance of the same problem over and over again; ... Read More

C++ Program to find permutation from merged permutations

Arnab Chakraborty
Updated on 08-Apr-2022 07:44:17

184 Views

Suppose we have an array A with 2n number of elements. We know a permutation of first n natural numbers is a set of numbers where 1 to n are stored and they are ordered in an arbitrary order. in the array A, there are two permutations of size n are merged together. When they are merged the relative order of the elements remains unchanged. So if a permutation p is like p = [3, 1, 2] some possible results are: [3, 1, 2, 3, 1, 2], [3, 3, 1, 1, 2, 2], [3, 1, 3, 1, 2, 2]. The ... Read More

C++ Program to check given candies can be split with equal weights or not

Arnab Chakraborty
Updated on 07-Apr-2022 11:24:17

218 Views

Suppose we have an array A with n elements. Amal and Bimal received n candies from their parents. Each candy weighs either 1 gram or 2 grams. They want to divide all candies among themselves fairly so that their total candies weight is same. We have to check whether we can do that or not. (We can not divide a candy into halves).Problem CategoryThe above-mentioned problem can be solved by applying Greedy problem-solving techniques. The greedy algorithm techniques are types of algorithms where the current best solution is chosen instead of going through all possible solutions. Greedy algorithm techniques are ... Read More

C++ Program to find minimum difference between strongest and weakest

Arnab Chakraborty
Updated on 07-Apr-2022 11:21:24

116 Views

Suppose we have an array A with n elements. There are n athletes in a game. They are numbered from 1 to n and arranged in left to right order. The strength of each athlete i is A[i]. We want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team. We want the strongest athlete from the first team to differ as little as possible from the weakest athlete from the second team. We have to find the minimum difference between their strength as mentioned above.Problem ... Read More

C++ Program to count operations to make all gifts counts same

Arnab Chakraborty
Updated on 07-Apr-2022 11:17:37

1K+ Views

Suppose we have two arrays A and B of size n each. There are n gifts and we want to give them to some children. The ith gift has A[i] candies and B[i] oranges. During one move, we can choose some gift and do one of the following operations −Take out exactly one candy from this gift (if available);Take out exactly one orange from this gift (if available);Take out exactly one candy and exactly one orange from this gift (if available).All gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: ... Read More

Advertisements