Found 7197 Articles for C++

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

102 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

130 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

163 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

142 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

117 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

Find element position in given monotonic Sequence in C++

Arnab Chakraborty
Updated on 24-Jul-2020 10:57:31

269 Views

ConceptWith respect of a given integer l and a monotonic increasing sequence −f(m) = am + bm [log2(m)] + cm^3 where (a = 1, 2, 3, …), (b = 1, 2, 3, …), (c = 0, 1, 2, 3, …) Remember, here, [log2(m)] indicates, taking the log to the base 2 and round the value down.As a result of this, if m = 1, the value is 0.if m = 2-3, the value is 1.if m = 4-7, the value is 2.if m = 8-15, the value is 3.Our task is to determine the value m such that f(m) = ... Read More

Find Duplicates of array using bit array in C++

Arnab Chakraborty
Updated on 24-Jul-2020 10:48:52

377 Views

ConceptWe have an array of n numbers, where n is maximum 32, 000. Now the given array may have duplicate entries and we do not know what n is. Now the question is arisen that with only4 Kilobytes of memory available, how would display or print all duplicates elements in the array?Inputarr[] = {2, 6, 2, 11, 13, 11}Output2 11 2 and 11 appear more than once in given array.Inputarr[] = {60, 50, 60}Output60MethodsNow we have 4 Kilobytes of memory which indicates we can address up to 8 * 4 * 210 bits.It should be noted that 32 * 210 ... Read More

Advertisements