Found 7346 Articles for C++

C++ Program to find maximal achievable diversity of music notes

Arnab Chakraborty
Updated on 08-Apr-2022 10:46:58

107 Views

Suppose we have a string S with n elements. Amal's song consists of n notes, which we will treat as positive integers. The diversity of a song is the number of different notes it contains. We want to make it more diverse. We cannot arbitrarily change the song. Instead, for each of the n notes in the song, she can either leave it as it is or increase it by 1. Given sequence is a song where integer is describing the notes, we have to find out the maximal, achievable diversity.Problem CategoryThe above-mentioned problem can be solved by applying Greedy ... Read More

C++ Program to count minimum problems to be solved to make teams

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

256 Views

Suppose we have an array A with n elements. There are n students in a university, n is even. The i-th student has programming skill equal to A[i]. The team leader wants to form n/2 teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal. Students can solve problems to increase their skill. If they solve one problem, their skill will be increased by 1. We have to find the minimum total number of problems students should solve to form ... Read More

C++ Program to count square root cube root and both in given range

Arnab Chakraborty
Updated on 08-Apr-2022 10:40:08

328 Views

Suppose we have a number n. We have to count the number of integers x, in range 1 to n such that, that x is a square of a positive integer number or a cube of a positive integer number (or both a square and a cube simultaneously).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 ... Read More

C++ Program to find maximum score of bit removal game

Arnab Chakraborty
Updated on 08-Apr-2022 08:39:41

103 Views

Suppose we have a binary string S with n bits. Amal and Bimal are playing a game. Amal moves first, then Bimal, and they move alternatively. During their move, the player can select any number (not less than one) of consecutive equal characters in S and remove them. After the characters are removed, the characters to the left side and to the right side of the removed block become adjacent. The game ends when the string becomes empty, and the score of each player will be the number of 1-characters deleted by them. They both wants to maximize their score. ... Read More

C++ Program to check string is strictly alphabetical or not

Arnab Chakraborty
Updated on 08-Apr-2022 08:33:51

252 Views

Suppose we have a string S with n letters in lowercase. A string is strictly alphabetical string, if it follows the following rule −Write an empty string to TThen perform the next step n times;At the i-th step take i-th lowercase letter of the Latin alphabet and insert it either to the left of the string T or to the right of the string T (c is the i-th letter of the Latin alphabet).We have to check whether S is strictly alphabetical string or not.Problem CategoryTo solve this problem, we need to manipulate strings. Strings in a programming language are ... Read More

C++ Program to find matrix with marked asterisks region

Arnab Chakraborty
Updated on 08-Apr-2022 08:28:16

131 Views

Suppose we have a n x n grid of characters with dots (.) and asterisks (*). All cells are marked as dot except two cells. We have to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes. If there are multiple solutions available, return any one of them.Problem CategoryAn array in the data structure is a finite collection of elements of a specific type. Arrays are used to store elements of the same type in consecutive memory locations. An array is assigned a particular name and it is referenced ... Read More

C++ Program to check string can be reduced to 2022 or not

Arnab Chakraborty
Updated on 08-Apr-2022 08:18:57

135 Views

Suppose we have a numeric string S with n digits. We perform the following operation with the string S, no more than once. We select two numbers i and j (1 ≤ i ≤ j ≤ n) and removes characters from S string from positions i to j. We have to check whether the string S can be reduced to 2022 in no more than one operations or not.Problem CategoryTo solve this problem, we need to manipulate strings. Strings in a programming language are a stream of characters that are stored in a particular array-like data type. Several languages specify ... Read More

C++ Program to check k rupees are enough to reach final cell or not

Arnab Chakraborty
Updated on 08-Apr-2022 08:15:00

88 Views

Suppose we have three numbers n, m and k. There is a n x m grid. we are currently at cell (0, 0) top left corner and we want to reach cell (n - 1, m - 1). We can move to the neighboring cells to the right or down. To reach down, it will take x rupees, and to reach right cell, it will take y rupees. We have to check whether we can reach cell (n - 1, m - 1) spending exactly k rupees or not. (The x and y are the current x and y coordinate ... Read More

C++ Program to get largest sum we can make from 256 and 32 from digits

Arnab Chakraborty
Updated on 08-Apr-2022 08:12:32

89 Views

Suppose we have four numbers a, b, c and d. In a box there are some numeri digits. There are 'a' number of digits 2, 'b' number of digits 3, 'c' number of digits 5 and 'd' number of digits 6. We want to compose numbers 32 and 256 from these digits. We want to make the sum of these integers as large as possible. (Each digit can be used no more than once, and unused digits are not counted in the sum).Problem CategoryThe above-mentioned problem can be solved by applying Greedy problem-solving techniques. The greedy algorithm techniques are types ... Read More

C++ Program to find winner of unique bidding game

Arnab Chakraborty
Updated on 08-Apr-2022 08:09:40

233 Views

Suppose we have an array A with n elements. There are n participants, the i-th participant chose the number A[i]. The winner of the bidding game is such a participant that the number he chose is unique and is minimal. We have to find the index of the participant who won the game. If not possible, return -1.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 ... Read More

Advertisements