Found 33676 Articles for Programming

Find if there is a path of more than k length from a source in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:28:25

165 Views

ConceptWith respect of a given graph, a source vertex in the graph and a number k(here k indicates the path length of graph between source vertex and destination vertex), our task is to determine if there is a simple path (without any cycle) beginning from given source and ending at any other vertex(i.e. destination). The graph is shown in following −InputSource s = 0, k = 64OutputTrueThere exists a simple path 0 -> 7 -> 1-> 2 -> 8 -> 6 -> 5 -> 3 -> 4, which has a total distance of 68 km which is more than 64.InputSource ... Read More

Find if neat arrangement of cups and shelves can be made in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:23:06

134 Views

ConceptWith respect of given three different types of cups (p[]) and saucers (q[]), and m numberof shelves, determine if neat arrangement of cups and shelves can be made.Now, arrangement of the cups and saucers will be neat if it follows the following rules −According to first rule, no shelf can contain both cups and saucers.According to second rule, there can be no more than 5 cups in any shelf.According to third rule, there can be no more than 10 saucers in any shelf.Inputp[] = {4, 3, 7} q[] = {5, 9, 10} m = 11OutputYesExplanationTotal cups = 14, shelves required ... Read More

Find if it is possible to get a ratio from given ranges of costs and quantities in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:22:07

104 Views

ConceptWith respect of the given range of cost from lowCost to upCost and range of quantity from lowQuant to upQuant, determine if it is possible to obtain a given ratio r where r=cost/quantity, and lowCost

Find if given vertical level of binary tree is sorted or not in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:20:26

132 Views

ConceptWith respect of a given binary tree, our task is to determine if a given vertical level of the binary tree is sorted or not.(With respect of this case, when two nodes are overlapping, verify if they form a sorted sequence in the level they lie.)Input2 / \ 3 6 / \ 8 5   / 7 Level l = -1OutputYesNodes in level -1 are 3 -> 7 which form a sorted sequence.Input2 / \ 3 7 \ / 4 5 Level l = 0OutputYesIt should be noted that nodes with value 4 and 5 are overlapping in the binary ... Read More

Find if an undirected graph contains an independent set of a given size in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:17:08

166 Views

ConceptWith respect of a given undirected graph, verify if it contains an independent set of size l. If there exists an independent set of size l print ‘Yes’, else print ‘No’. It should be noted that an independent set in a graph is defined as a set of vertices which are not directly connected to each other.InputL = 4, graph = [[1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [1, 1, 1, 1, 1], [0, 0, 1, 1, 0], [0, 0, 1, 0, 1]];OutputYesThe above graph contains an independent set of size 4 (vertices 0, 1, 3, 4 ... Read More

Find Four points such that they form a square whose sides are parallel to x and y axes in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:11:28

1K+ Views

ConceptWith respect of given ‘n’ pair of points, our task is to determine four points so that they form a square whose sides are parallel to x and y axes or else display “No such square”. It should be noted that if more than one square is possible then select the one with the maximum area.Inputn = 6, points = (2, 2), (5, 5), (4, 5), (5, 4), (2, 5), (5, 2)OutputSide of the square is: 3, points of the square are 2, 2 5, 2 2, 5 5, 5ExplanationThe points 2, 2 5, 2 2, 5 5, 5 form ... Read More

Find four missing numbers in an array containing elements from 1 to N in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:08:21

169 Views

ConceptWith respect of a given array of unique integers where each integer of the given array lies in the range [1, N], the size of array is (N-4) and no single element is repeated. So, four numbers, from 1 to N, are missing in the array. Determine the 4 missing numbers in sorted order.Inputarr[] = {3, 6, 7, 4, 10}Output1 2 5 8 9Inputarr[] = { 2, 8, 4, 13, 6, 11, 9, 5, 10 }Output1 3 7 12MethodNow a simple O(N) solution is to implement an auxiliary array of size N to indicate or markvisited elements. Visit the input ... Read More

C++ find four factors of N with maximum product and sum equal to N .

Arnab Chakraborty
Updated on 24-Jul-2020 11:06:49

143 Views

ConceptWith respect of a given integer N, our task is to determine all factors of N print the product of four factors of N so that −The sum of the four factors is equal to N.The product of the four factors is largest.It has been seen that if it is impossible to find 4 such factors then print “Not possible”.It should be noted that all the four factors can be equal to each other to maximize the product.Input24OutputAll the factors are -> 1 2 4 5 8 10 16 20 40 80 Product is -> 160000Select the factor 20 four ... Read More

Find four factors of N with maximum product and sum equal to N - Set-2 in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:01:57

118 Views

ConceptWith respect of a given integer N, our task is to determine all factors of N and print the product of four factors of N so that −The sum of the four factors is equal to N.The product of the four factors is largest.It has been seen that if it is impossible to determine 4 such factors then print “Not possible”. It should be noted thatall the four factors can be equal to each other to maximize the product.InputN = 60OutputAll the factors are -> 1 2 3 4 5 6 10 12 15 20 30 60 Product is -> ... Read More

Find First element in AP which is multiple of given Prime in C++

Arnab Chakraborty
Updated on 24-Jul-2020 10:58:32

76 Views

ConceptWith respect of given first term (A) and common difference (d) of an Arithmetic Progression, and a prime number (P), our task is to determine the position of the first element in the given AP which is treated as a multiple of the given prime number P.InputA = 3, d = 4, P = 5Output3ExplanationThe fourth term of the given AP is a multiple of prime number 5.First Term = 3Second Term = 3+4 = 7Third Term = 3+2*4 = 11Fourth Term = 3+3*4 = 15MethodAssume the term be AN. As a result of this, AN = (A + (N-1)*d)So, ... Read More

Advertisements