Found 7347 Articles for C++

C++ program to find out number of changes required to get from one end to other end in a grid

Arnab Chakraborty
Updated on 02-Mar-2022 12:37:34

110 Views

Suppose, we are given a grid of dimensions x * y that contains two types of cells, blocked and unblocked. Blocked cells mean that the cells aren't accessible and unblocked means that the cells are accessible. We represent the grid in a 2D array where the blocked cells are given as '#' and the unblocked cells are given as '.'. Now, we have to reach from the cell (0, 0) to cell (x, y). We can perform only two moves, we can either go right of a cell or go down from a cell. We have to keep in mind ... Read More

C++ Program to find out the least amount of money required to subscribe to the OTT services

Arnab Chakraborty
Updated on 02-Mar-2022 12:35:09

158 Views

Suppose, a telecom operator has introduced a service called "all-in-one" which provides access to n OTT content providers at a fixed price of k dollars. Now, if we have to subscribe to the OTT platforms directly, we have to pay an individual amount of fee to each of the platforms. We do not need subscriptions to every platform at all months, so we have to find a way to cost-effectively use their services. The starting month in which we need the service of platform i is given in the array start_month and the ending month is given in the array ... Read More

C++ Program to check cats words are right or not with colored hats

Arnab Chakraborty
Updated on 25-Feb-2022 13:16:39

125 Views

Suppose we have an array A with N elements. Consider there are N cats and they are numbered from 1 to N. Each cat is wearing a hat and ith cat says "there are exactly A[i] number of different colors among the N-1 hats owned by the cats except me". We have to check whether there exists a sequence of colors of the hats which is consistent with the remarks of the cats.So, if the input is like A = [1, 2, 2], then the output will be True, because if cat 1, 2 and 3 wears hats in colors ... Read More

C++ program to check we can buy product with given money or not

Arnab Chakraborty
Updated on 25-Feb-2022 13:02:27

175 Views

Suppose we have a number N. A cake seller is selling cakes with 40 rupees, and doughnuts with 70 rupees each. We have to check whether we can buy some of them with exactly N rupees or not.So, if the input is like N = 110, then the output will be True, because 40 + 70 = 110.To solve this, we will follow these steps −o := false Define a function dfs(), this will take i, if i > n, then:    return false if i is same as n, then:    return true if dfs(i + 40), then:   ... Read More

C++ Program to check we can remove all stones by selecting boxes

Arnab Chakraborty
Updated on 25-Feb-2022 12:57:26

106 Views

Suppose we have an array A with N elements. Consider there are N boxes and they are arranged in a circle. The ith box contains A[i] stones. We have to check whether we can remove all stones from the boxes by repeatedly performing the operation: Select a box say ith box. For each j in range 1 to N, remove exactly j stones from the (i+j)th box. Here (N+k)th box is termed as kth box. This operation cannot be performed if a box does not contain sufficient number of stones.So, if the input is like A = [4, 5, 1, ... Read More

C++ program to find last value of matrix with given constraints

Arnab Chakraborty
Updated on 25-Feb-2022 12:51:54

108 Views

Suppose we have a list of numbers A with N elements in it. The elements are 1, 2 or 3, Consider a number X[1][j] = A[j] where j is in range 1 to N. And X[i][j] = |X[i-1][j] - X[i-1][j+1]| where i is in range 2 to N and j is in range 1 to N+1-i. We have to find the value of X[i][j].So, if the input is like A = [1, 2, 3, 1], then the output will be 1, becauseX[1][1] to X[1][4] are 1, 2, 3, 1 X[2][1], X[2][2], X[2][3] are |1-2| = 1, |2 - 3| = ... Read More

C++ Program to find minimum possible unlancedness of generated string T

Arnab Chakraborty
Updated on 25-Feb-2022 12:36:39

76 Views

Suppose we have a string S with possible characters '0', '1' or '?'. We want to make string T by replacing each occurrence of '?' with 0 or 1. The unbalancedness of T is like: maximum of the all absolute differences between number of occurrences of 0 and 1 in between lth and rth character in S where 0 1; if (check(S, Mid)) R = Mid - 1; else L = Mid + 1; } return R + 1; } int main() { string S = "0??0"; cout

C++ Program to find out the maximum rated parts set

Arnab Chakraborty
Updated on 25-Feb-2022 12:28:29

108 Views

Suppose, there is a manufacturer that makes specific parts for a particular product. The manufacturer has n different variations of the parts, and the parts have a specific rating on three criteria. The ratings of the n products are given in the array 'ratings' where each element is of the format (A, B, C) where A, B, and C are different rating criteria of the product. Now, an OEM wants to buy m parts for each product they make from the manufacturer of the parts. The OEM chooses the parts satisfying the below conditions −Two or more units of the ... Read More

C++ Program to find out if a round trip is possible from a particular city

Arnab Chakraborty
Updated on 25-Feb-2022 11:53:13

414 Views

Suppose, there are n cities and m roads are connecting them. Each road is unidirectional, and it takes a particular amount of time to reach from the source city to the destination city. The information of the roads is given in the array roads where each element is of the format (source, destination, time). Now, a person is traveling from one city to another city and the trip has to be a round-trip. A trip can be called round-trip when the person starts from a particular city, goes through one or more roads, and finishes the trip in the same ... Read More

C++ program to find out the maximum value of i

Arnab Chakraborty
Updated on 25-Feb-2022 11:41:05

127 Views

Suppose, we have a permutation of integers 'seq' and an array of integer pairs 'pairs' of size m that contains integers 0 to n - 1. Now, we perform the following operation on seq as many times as possible so that seq[i] = i (0 ≤ i < n) is maximized.We have to choose an integer j where 0

Advertisements