Found 7197 Articles for C++

C++ Program to find out the number of illuminated cells in a grid

Arnab Chakraborty
Updated on 02-Mar-2022 08:12:53

211 Views

Suppose, we are given a grid of dimensions h * w. The cells in the grid can contain either bulbs or obstacles. A light bulb cell illuminates itself and the cells in its right, left, up, and down and the light can shine through the cells unless an obstacle cell blocks the light. An obstacle cell can not be illuminated and it blocks the light from a bulb cell from reaching the other cells. So, given the position of the bulb cells in the grid in array 'bulb' and the position of obstacle cells in the array 'obstacles', we have ... Read More

C++ Program to find out the number of bridge edges in a given graph

Arnab Chakraborty
Updated on 02-Mar-2022 08:05:16

480 Views

Suppose, we are given an unweighted, undirected graph that contains n vertices and m edges. A bridge edge in a graph is an edge whose removal causes the graph to be disconnected. We have to find out the number of such graphs in a given graph. The graph does not contain parallel edges or self-loops.So, if the input is like n = 5, m = 6, edges = {{1, 2}, {1, 3}, {2, 3}, {2, 4}, {2, 5}, {3, 5}}, then the output will be 1.The graph contains only one bridge edge that is {2, 4}.To solve this, we will ... Read More

C++ Program to find out the number of sides that a polygon has inside a grid

Arnab Chakraborty
Updated on 02-Mar-2022 12:55:32

479 Views

Suppose, we are given a grid of dimensions h x w. There are two types of cells in the grid, white and black cells. White cells are represented by '.', whereas black cells are represented by '#'. Now the grid has multiple black cells in it that form a polygon. We have to find out the number of sides that the polygon has. It is to be noted, that the outermost cells of the grid are always white.So, if the input is like h = 4, w = 4, grid = {"....", ".##.", ".##.", "...."}, then the output will be ... Read More

C++ program to find out the number of pairs in an array that satisfy a given condition

Arnab Chakraborty
Updated on 02-Mar-2022 07:50:50

2K+ Views

Suppose, we are given n numbers in array nums. We have to choose a pair of two numbers from the array, and there is a condition that the difference of their positions in the array is equal to the sum of the two numbers. There can be a total of n(n - 1)/2 number of total pairs from the given array of numbers. We have to find out the total number of such pairs from the array.So, if the input is like n = 8, nums = {4, 2, 1, 0, 1, 2, 3, 3}, then the output will be ... Read More

C++ Program to check if given numbers are coprime or not

Arnab Chakraborty
Updated on 02-Mar-2022 07:47:17

2K+ Views

Suppose, we have n integers in an array nums. We have to find out if the numbers in the array are pairwise coprime, setwise coprime, or not coprime.Two numbers nums[i] and nums[j] are said to be pairwise coprime if gcd(nums[i], nums[j]) = 1. This should hold for every number pair in the array and i < j.The numbers are said to be setwise coprime if gcd(nums[i]) = 1.If they are neither, we say that they are not coprime.So, if the input is like n = 4, nums = {7, 11, 13, 17}, then the output will be the numbers are ... Read More

C++ Program to check if two stacks of letters can be emptied or not

Arnab Chakraborty
Updated on 02-Mar-2022 07:41:49

176 Views

Suppose, there are 2n number of letters and each of them has an integer number between 1 to n written on them. There are exactly two letters that have the same number written on them. These letters are arranged into m stacks and stack i has letters stack[i] on it. Our task is to empty all the stacks in the following mannerWe have to choose any two stacks and remove the top letter from both of them.The letters that we have removed must have the same number on both of them.If we can empty the m stacks in this manner, ... Read More

C++ Program to find out the maximum amount of money that can be made from selling cars

Arnab Chakraborty
Updated on 02-Mar-2022 07:17:43

299 Views

Suppose, there is a demand for red and blue cars for sale. An automobile company decides to sell p red cars and q blue cars of different prices. Currently, the company has 'a' number of red cars, 'b' number of blue cars, and 'c' numbers of colorless cars (the cars are yet to be painted) in their stock. The values of the different cars are given in arrays A, B, and C. So, the company has to sell p + q number of cars in a day and they have to make maximum profit from them. The colorless cars can ... Read More

C++ program to check if two images match after rotation and translation

Arnab Chakraborty
Updated on 02-Mar-2022 07:09:04

241 Views

Suppose, there are two n * n pixel square images first and second. The pixels can either be black or white. The images are given in a matrix representation where if a pixel is black it is represented as 'x' and if it is white, it is represented as '.'. We have to check the second image matches with the first image after 90° rotations and translations. If it does we return true, otherwise, we return false.So, if the input is like n = 4, first = {"..x.", "x.x.", "x.xx", "xx.."}, second = {"..xx", "x.xx", ".x.x", "..x."}, then the output ... Read More

C++ Program to find out the maximum amount of score that can be decreased from a graph

Arnab Chakraborty
Updated on 02-Mar-2022 06:59:39

322 Views

Suppose, there is a weighted, undirected graph that has n vertices and m edges. The score of the graph is defined as the addition of all the edges weights in the graph. The edge weights can be negative, and if they are removed the score of the graph increases. What we have to do, we have to make the score of the graph minimum by removing the edges from the graph while keeping the graph connected. We have to find out the maximum amount of score that can be decreased.The graph is given in an array 'edges', where each element ... Read More

C++ Program to find out the number of cells to block in a grid to create a path

Arnab Chakraborty
Updated on 02-Mar-2022 06:54:00

411 Views

Suppose, there is a grid of dimensions h * w. There is a robot in cell position (0, 0) and it has to go to the position (h - 1, w - 1). There are two types of cells in a grid, blocked and unblocked. The robot can pass through the unblocked cells but cannot pass through the blocked cells. The robot can go in four directions; it can go left, right, up, and down. But the robot may go in any direction from a cell to another (ignoring the previous cell it was in), so we have to make ... Read More

Advertisements