C++ Program to Find Opponent in a Circular Standing of Persons

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

173 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

Get Length of Longest Subsequence in N Times Copied Sequence

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

216 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

Count Ordinary Numbers in Range 1 to N using C++

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

775 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

Find Permutation from Merged Permutations in C++

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

270 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

Check If Given Candies Can Be Split with Equal Weights in C++

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

305 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

Find Minimum Difference Between Strongest and Weakest in C++

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

189 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

Count Operations to Make All Gifts Counts Same in C++

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

Find Winner and Final Price in a Second Price Auction Event

Arnab Chakraborty
Updated on 07-Apr-2022 11:14:09

331 Views

Suppose we have an array A with n elements. There is a special type of an auction, which is called the second-price auction. In a regular auction, n bidders place a bid which is price a bidder ready to pay. The auction ends, when each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. But here, he pay not the price he offers, but the highest price among the offers of other participants (the second-price auction). A[i] is the price offered by ... Read More

C++ Program to Find Array of Candy Distribution to M Friends

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

321 Views

Suppose we have two numbers n and m. Amal has n candies and m friends. He wants to make a present with candies to each friend. Amal is planning to present all candies and he wants to do this in the most equal manner. He wants to choose such A[i], where A[i] is the number of candies in the i-th friend's present, the maximum A[i] differs from the least A[i] as little as possible. We have to find the array A.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an ... Read More

C++ Program for Distribution of Apples for Two Mice

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

436 Views

Suppose we have a number n and two arrays A and B of different sizes. There are two mice: m1 and m2. We put n apples in front of them. We know which apples m1 likes. Similarly, we also know which apples m2 likes. We do not want any conflict between the mice (as they may like the same apple), so we decided to distribute the apples between the mice on our own. We are going to give some apples to m1 and some apples to m2. It doesn't matter how many apples each mouse gets but it is important ... Read More

Advertisements