Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 220 of 377

Find original numbers from gcd() every pair in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 427 Views

ConceptWith respect of a given array array[] containing GCD of every possible pair of elements of another array, our task is to determine the original numbers which are used to compute the GCD array.Inputarray[] = {6, 1, 1, 13}Output13 6 gcd(13, 13) = 13 gcd(13, 6) = 1 gcd(6, 13) = 1 gcd(6, 6) = 6Inputarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 8, 11, 13, 3, 3}Output13 11 8 6 6MethodAt first, sort the array in decreasing order.Largest element will always be one of the ...

Read More

Find number of edges that can be broken in a tree such that Bitwise OR of resulting two trees are equal in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 347 Views

ConceptWith respect of a given tree with m nodes and a number associated with every node, we canbreak any tree edge which will result in the formation of 2 new trees. Here, we have to count the number of edges in this way so that the Bitwise OR of the nodes present in the two trees constructed after breaking that edge are equal. It should be noted that the value ofevery node is ≤ 10^6.Inputvalues[]={1, 3, 1, 3}      1    / | \   2 3 4Output2Here, the edge between 1 and 2 can be broken, the Bitwise ...

Read More

Find nth term of a given recurrence relation in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 294 Views

ConceptAssume bn be a sequence of numbers, which is denoted by the recurrence relation b1=1 and bn+1/bn=2n. Our task is to determine the value of log2(bn) for a given n.Input6Output15Explanationlog2(bn) = (n * (n - 1)) / 2 = (6*(6-1))/2 = 15Input200Output19900Methodbn+1/bn = 2nbn/bn-1 = 2n-1...b2/b1 = 21, We multiply all of above in order to attain(bn+1/bn).(bn/n-1)……(b2/b1) = 2n + (n-1)+……….+1So, bn+1/b1 = 2n(n+1)/2Because we know, 1 + 2 + 3 + ………. + (n-1) + n = n(n+1)/2So, bn+1 = 2n(n+1)/2 . b1; Assume the initial value b1 = 1So, bn+1 = 2sup>n(n+1)/2Now substituting (n+1) for n, we get, ...

Read More

Find minimum time to finish all jobs with given constraints in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 446 Views

ConceptWith respect of a given array of jobs with different time requirements, there exists k identical assignees available and we are also provided how much time an assignee consumesto do one unit of the job. Our task is to determine the minimum time to complete all jobs with following constraints.The first constraint is that an assignee can be assigned only contiguous jobs.Here, for example, an assignee can be assigned jobs at position 1 and 2, but not at position 3, in an array.The second constraint is that two assignees cannot share (or co-assigned) a job, that means, a job cannot ...

Read More

Find minimum adjustment cost of an array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 478 Views

ConceptWith respect of a given array of positive integers, we replace each element in the array so that the difference between adjacent elements in the array is either less than or equal to a given target. Now, our task to minimize the adjustment cost, that is the sum of differences between new and old values. So, we basically need to minimize Σ|A[i] – Anew[i]| where 0 ≤ i ≤ n-1, n is denoted as size of A[] and Anew[] is denoted as the array with adjacent difference less than or equal to target. Let all elements of the array is ...

Read More

Find maximum points which can be obtained by deleting elements from array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 182 Views

ConceptWith respect of a given array A having N elements and two integers l and r where, 1≤ ax ≤ 105 and 1≤ l≤ r≤ N. We can select any element of the array (let’s say ax) and delete it, and also delete all elements equal to ax+1, ax+2 … ax+R and ax-1, ax-2 … ax-L from the array. This step will cost ax points. Our task is to maximize the total cost after deleting all the elements from the array.Input2 1 2 3 2 2 1 l = 1, r = 1Output8Here, we choose 2 to delete, then (2-1)=1 ...

Read More

Find maximum operations to reduce N to 1 in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 163 Views

ConceptWith respect of given two numbers P and Q ( P and Q can be up to 10^6 ) which forms a number N = (P!/Q!). Our task is to reduce N to 1 by performing maximum number of operations possible. Remember, in each operation, one can replace N with N/X if N is divisible by X. Determine the maximum number of operations that can be possible.InputA = 7, B = 4Output4ExplanationN is 210 and the divisors are 2, 3, 5, 7InputA = 3, B = 1Output2ExplanationN is 6 and the divisor are 2, 3.MethodIt has been observed that factorization ...

Read More

Find maximum N such that the sum of square of first N natural numbers is not more than X in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 514 Views

ConceptWith respect of a given integer X, our task is to determine the maximum value N so that the sum of first N natural numbers should not exceed X.InputX = 7Output22 is the maximum possible value of N because for N = 3, the sum of the series will exceed X i.e. 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14InputX = 27Output33 is the maximum possible value of N because for N = 4, the sum of the series will exceed X i.e. 1^2 + 2^2 + 3^2 + 4^2 = 1 + 4 + ...

Read More

Find maximum length Snake sequence in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 405 Views

ConceptWith respect of a given grid of numbers, determine maximum length Snake sequence and display it. It has been observed that if multiple snake sequences exist with the maximum length, display any one of them.Actually, a snake sequence is made up of adjacent numbers in the grid so that for each number, the number on the right or the number below it is either +1 or -1 its value. Here, for instance, if we are at location (a, b) in the grid, we can either move right i.e. (a, b+1) if that number is ± 1 or move down i.e. ...

Read More

Find maximum distance between any city and station in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Jul-2020 512 Views

ConceptWith respect of the given number of cities N numbered from 0 to N-1 and the cities in which stations are located, our task is to determine the maximum distance between any city and its nearest station. It should be noted that the cities with stations can be given in any order.InputnumOfCities = 6, stations = [2, 4]Output2InputnumOfCities = 6, stations = [4]Output4The following figure indicates the first example containing 6 cities and the cities with stations highlighted with green color. So, in this case, the farthestcities from its nearest stations are 0 at a distance of 2. Hence maximum ...

Read More
Showing 2191–2200 of 3,768 articles
« Prev 1 218 219 220 221 222 377 Next »
Advertisements