Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 141 of 719
325 Views
Suppose we have two arrays X and H. Both are with N elements, also have another two numbers D and A. Consider in a story, a silver fox is fighting with N monsters. The monsters are standing in a row, coordinate of ith monster is X[i], and its health is H[i]. Silver fox can use bombs to attack monsters. Dropping bomb at location x will damage all monsters within the range of x - D to x + D. Their health will be reduced by A. When all monsters have 0 health left, then the fox wins. We have to ... Read More
175 Views
Suppose we have an adjacency matrix of a graph G. We have to check whether we can divide the vertices into non-empty sets V1, ... Vk, such that: every edge connects two vertices belonging to two adjacent sets. If the answer is yes, we have to find the maximum possible value of sets k, in such division.So, if the input is like010110101001010100101000100000010000then the output will be 4StepsTo solve this, we will follow these steps −Define an array dp of size: 210. n := size of matrix fl := 1 ans := 0 for initialize i := 0, when i < ... Read More
310 Views
Suppose we have two arrays p and c both are with D number of elements each, and another number G. Consider in a coding contest, each problem has its score based on difficulty. The problem p[i] has score 100i. These p[1] + ... + p[D] problems are all of the problems present in the contest. a user in the coding site has a number total_score. The total_score of an user is the sum of the following two elements.Base score: the sum of score of all solved problemsBonus: when a user solves all problems with a score of 100i, he or ... Read More
201 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
374 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
421 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
267 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
268 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
325 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
561 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