Found 7197 Articles for C++

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

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

340 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

189 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

200 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

155 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

136 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

356 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

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

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

275 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

194 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

366 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

169 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

Advertisements