Found 7347 Articles for C++

C++ Program to find maximum possible smallest time gap between two pair of clock readings

Arnab Chakraborty
Updated on 02-Mar-2022 11:27:24

117 Views

Suppose we have an array D with N elements. Consider in a code festival there are N+1 participants including Amal. Amal checked and found that the time gap between the local times in his city and the i-th person's city was D[i] hours. The time gap between two cities: For any two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is minimum of d and 24−d hours.Here, we are using 24-hour notation. Then, ... Read More

C++ Program to find pairs of sequences where sequence holds minimum and maximum elements

Arnab Chakraborty
Updated on 02-Mar-2022 11:23:37

268 Views

Suppose we have three numbers N, M and K. There are N horizontal rows and M vertical rows. We shall write an integer in between 1 and K on each cell, and define sequences A and B, such that −for each i in range 1 to N, A[i] is minimum of all elements in ith rowfor each j in range 1 to M, B[j] is maximum of all elements in jth columnWe have to find the number of pairs (A, B). If the answer is too large, return result mod 998244353.So, if the input is like N = 2; M ... Read More

C++ Program to find out if a palindromic matrix can be made from a given matrix

Arnab Chakraborty
Updated on 02-Mar-2022 11:18:46

318 Views

Suppose, we are given a matrix with dimensions h x w. The matrix contains English letters. We have to create another matrix that will contain palindromic rows and columns, i.e. each row and column would be palindromes. To do that, any arrangement of rows and columns can be done from the given matrix; but no element can be changed, i.e. an 'a' cannot be changed to a 'b'. If that is possible to make a palindromic matrix from the given matrix, we return true; or otherwise, we return false.So, if the input is like h = 4, w = 4, ... Read More

C++ Program to find out number of employees of different skill level to be transferred

Arnab Chakraborty
Updated on 02-Mar-2022 11:13:44

150 Views

Suppose, there are n employees in a company. Each of the employees is given a rank based on their skills. The ranks are numbered from 1 to k. The number of employees having a rank i is given in the array skill, where skill[i] represents the number of employees having rank i. Now, a new branch of the company has opened and employees of different skills have to be transported to that branch. The number of employees to be sent to that branch is m. We have to find a way so that we can transfer m employees of different ... Read More

C++ Program to find out the minimum difference value in n integer pairs

Arnab Chakraborty
Updated on 02-Mar-2022 11:09:42

165 Views

Suppose, we are given two arrays a and b that have a total of n and m values in them respectively. We have to make n or m number of pairs (whichever is minimum) using values from the two arrays. A pair must contain a value from array a and another one from array b. We have to make the pairs in such a way so that the difference of the value in the pairs is minimum and the same. We print the value as output.So, if the input is like n = 4, m = 4, a = {2, ... Read More

C++ Program to find out the sum of shortest cost paths for all given triplets

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

230 Views

Suppose, there are n cities and m roads between the cities. The m roads are given to us in an array of roads where the roads are in the format {aource, destination, weight}. Now, we define a triplet (s, t, k) where s, t, and k are cities. Now we have to calculate the minimum time needed to get from city s to city t. To visit t from s, only cities within 1 to k can be visited. If city t is unreachable from s, then we return 0. We have to calculate the minimum time for all triplets ... Read More

C++ program to find out the shortest cost path in a given graph for q queries

Arnab Chakraborty
Updated on 02-Mar-2022 11:00:37

436 Views

Suppose, we are given a graph that contains n vertices and is minimally connected. The edges are given to us an array where the edges are given in a {source, dest, weight} format. Now, we are given q number of queries where each query is of the format {source, destination}. We have to find the shortest cost path from the source to the destination via vertex k. We print the cost of the path for each query.So, if the input is like n = 6, q = 3, k = 1, edges = {{1, 2, 2}, {1, 3, 4}, {3, ... Read More

C++ Program to find out the number of operations to maximize the number of even-numbered cells in a grid

Arnab Chakraborty
Updated on 02-Mar-2022 10:56:05

72 Views

Suppose, we are given a grid of dimensions h * w. Every cell in the grid has a specific value assigned to it. We have to maximize the cells having an even value. To do that, we can select a cell that has not been selected before, and then decrease the value by 1 of the current cell and increase the value by 1 of another cell that is located vertically or horizontally adjacent to the current cell. We print out the number of operations and the cell numbers of the increase and decrease operations. The output will be in ... Read More

C++ Program to find out the maximum amount of profit that can be achieved from selling wheat

Arnab Chakraborty
Updated on 02-Mar-2022 10:23:18

236 Views

Suppose, there is n number of cities that are connected with m roads. The roads are unidirectional, the roads can only go from source to destination and not the opposite. The roads are given in the array 'roads' in format {source, destination}. Now, in the cities, wheat is sold at different prices. The price of wheat across the cities is given in an array 'price', where the i-th value is the price of wheat in the i-th city. Now, a traveler can buy wheat from any of the cities and can reach any of the cities (if it is permissible) ... Read More

C++ program to find out the number of ways a grid with boards can be colored

Arnab Chakraborty
Updated on 02-Mar-2022 10:17:54

304 Views

Suppose, we are given a grid that has 2 rows and n columns. The grid has to be covered by n boards without one board getting over another. Now, the boards have to be colored by any one color between red, blue, and green. Two boards that are adjacent to each other cannot be colored by the same color and if not necessary, all colors do not have to be used. The configuration of the grid is given in the array 'grid', where a particular board in the grid is represented using the same English letter and different boards are ... Read More

Advertisements