Found 33676 Articles for Programming

Find element position in given monotonic Sequence in C++

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

270 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

378 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 distinct elements common to all rows of a Matrix in C++

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

287 Views

ConceptWith respect of a given an m x m matrix, the problem is to determine all the distinct elements common to all rows of the matrix. So the elements can be displayed in any order.Inputmat[][] = { {13, 2, 15, 4, 17}, {15, 3, 2, 4, 36}, {15, 2, 15, 4, 12}, {15, 26, 4, 3, 2}, {2, 19, 4, 22, 15} }Output2 4 15MethodsFirst Method: Implement three nested loops. Verify if an element of 1st row is present in all the subsequent rows. Here, time Complexity is O(m^3). Additional space could be required to control the duplicate elements.Second Method: ... 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
Updated on 24-Jul-2020 10:43:49

187 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
Updated on 24-Jul-2020 10:40:50

149 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 bitonic point in given bitonic sequence in Python

Arnab Chakraborty
Updated on 28-Aug-2020 12:14:27

573 Views

Suppose we have a bitonic sequence, we have to find the Bitonic Point in it. As we know a Bitonic Sequence is a sequence of numbers which is first strictly increasing then after a certain point it is strictly decreasing. This point is bitonic point. For only increasing or only decreasing sequences, bitonic points are not available.So, if the input is like [7, 8, 9, 12, 10, 6, 3, 2], then the output will be 12To solve this, we will follow these steps −define a function binary_search(array, l, r)if l array[m + 1], then −return mif array[m] < array[m ... Read More

Find array with k number of merge sort calls in Python

Arnab Chakraborty
Updated on 28-Aug-2020 12:03:31

135 Views

Suppose we have two numbers a and b, we have to find an array containing values in range [1, a] and requires exactly b number of calls of recursive merge sort function.So, if the input is like a = 10, b = 15, then the output will be [3, 1, 4, 6, 2, 8, 5, 9, 10, 7]To solve this, we will follow these steps −Define a function solve() . This will take left, right, array, bif b < 1 or left + 1 is same as right, thenreturnb := b - 2mid := (left + right) / 2temp := ... Read More

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

Arnab Chakraborty
Updated on 23-Jul-2020 09:13:11

197 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 an element which divides the array in two subarrays with equal product in Python

Arnab Chakraborty
Updated on 28-Aug-2020 10:01:27

154 Views

Suppose we have an array of size N; we have to find an element which divides the array into two different sub-arrays with equal product. Return -1 if no such partition is possible.So, if the input is like [2, 5, 3, 2, 5], then the output will be 3 then subarrays are: {2, 5} and {2, 5}To solve this, we will follow these steps −n := size of arraymultiply_pref := a new listinsert array[0] at the end of multiply_preffor i in range 1 to n, doinsert multiply_pref[i-1]*array[i] at the end of multiply_prefmultiply_suff := a list of size n, and fill ... Read More

Find an element in an array such that elements form a strictly decreasing and increasing sequence in Python

Arnab Chakraborty
Updated on 28-Aug-2020 09:44:39

648 Views

Suppose we have an array of positive numbers; we have to check a point/item up to which items create a strictly decreasing sequence first followed by a sequence of strictly increasing integers. These are the following properties: We have to keep in mind that the sequences must be of minimum length 2Also, we have taken care that the last value of the decreasing sequence is the first value of the increasing sequence.So, if the input is like {5, 4, 3, 4}, then the output will be 3, as {5, 4, 3} is strictly decreasing then {3, 4} is strictly increasing.To ... Read More

Advertisements