Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 222 of 377

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 24-Jul-2020 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 First element in AP which is multiple of given Prime in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 24-Jul-2020 120 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
Arnab Chakraborty
Updated on 24-Jul-2020 317 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
Arnab Chakraborty
Updated on 24-Jul-2020 414 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

Find d to maximize the number of zeros in array c[] created as c[i] = d*a[i] + b[i] in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 24-Jul-2020 234 Views

ConceptWith respect of two given arrays of M integers, assume an array C, where the i-th integer will be d*a[i] + b[i] where d is indicated as any arbitrary real number. Our task is to display or print d such that array C has largest number of zeros and also prints the number of zeros.Inputa[] = {15, 40, 45} b[] = {4, 5, 6}OutputValue of d is: -0.133333 The number of zeros in array C is: 1 If we choose d as -0.133333 then we get one zero in the array C which is the maximum possible.MethodsWe follow the below ...

Read More

Find combined mean and variance of two series in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 24-Jul-2020 183 Views

ConceptWith respect of two given two different series arr1[b] and arr2[a] of size b and a. Our task is to determine the mean and variance of combined series.InputArr1[] = { 24, 46, 35, 79, 13, 77, 35 }; Arr2[] = { 66, 68, 35, 24, 46 };OutputMean1: 44.1429 Mean2: 47.8 StandardDeviation1: 548.694 StandardDeviation2: 294.56 Combined Mean: 45.6667 d1 square: 2.322 d2_square: 4.5511 Combined Variance: 446.056MethodNow suppose, n1= No. of observations in 'region 1'n2= No. of observations in 'region 1'X1= mean of region 1.X2=mean of region 2.S1=standard deviation of region 1.S2=standard deviation of region 2.S12 = variance of region 1.S22 = ...

Read More

Find an integer X which is divisor of all except exactly one element in an array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Jul-2020 245 Views

ConceptWith respect of a given array of integers, our task is to determine an integer B which isthe divisor of all except for exactly one element in the given array.It should be noted that the GCD of all the elements is not 1.Input arr[] = {8, 16, 4, 24}Output 8 8 is the divisor of all except 4.Input  arr[] = {50, 15, 40, 41}Output  5 5 is the divisor of all except 41.MethodWe create a prefix array A such that position or index i contains the GCD of all the elements from 1 to i. In the similar way, create a suffix array C ...

Read More

Find a permutation that causes worst case of Merge Sort in C

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Jul-2020 345 Views

ConceptWith respect of a given set of elements, determine which permutation of these elements would result in worst case of Merge Sort?We know, asymptotically, merge sort always consumes O(n log n) time, but the cases that need more comparisons generally consume more time in practice. Now we basically require determining a permutation of input elements that would lead to largest number of comparisons when sorted implementing a typical Merge Sort algorithm.Example Consider the below set of elements as Sorted array 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Resultant input array that will result ...

Read More

Find a pair with given sum in a Balanced BST in Java

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Jul-2020 275 Views

ConceptWith respect of a given Balanced Binary Search Tree and a target sum, we write a function that returns true if there is a pair with sum equals to target sum, otherwise return false. In this case, expected time complexity is O(n) and only O(Logn) extra space can beimplemented. Here, any modification to Binary Search Tree is not permitted.We have to note that height of a Balanced BST is always O(Logn).ExampleMethodAccording to the Brute Force Solution, we consider each pair in BST and verify whether the sum equals to X. The time complexity of this solution will be O(n^2).Now a ...

Read More

Find a number which give minimum sum when XOR with every number of array of integer in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Jul-2020 334 Views

ConceptWith respect of given array Arr[] of non-negative integers, the task is to determine an integer X such that (Arr[0] XOR X) + (Arr[1] XOR X) + … + Arr[n – 1] XOR X is minimum possible.Input Arr[] = {3, 4, 5, 6, 7}Output X = 7, Sum = 10ApproachSo we will verify ‘i’th bit of every number of array in binary representation and consider and count those numbers containing that ‘i’th bit set to ‘1’ because these set bits will contribute to maximize the sum instead of minimize. As a result of this, we have to build this set ‘i’th bit ...

Read More
Showing 2211–2220 of 3,768 articles
« Prev 1 220 221 222 223 224 377 Next »
Advertisements