Found 33676 Articles for Programming

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

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

202 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

157 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

139 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

357 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

278 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

198 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

368 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

171 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

214 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

771 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

Advertisements