Found 10783 Articles for Python

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

Arnab Chakraborty
Updated on 25-Aug-2020 09:21:54

151 Views

Suppose we have an array of distinct numbers where each number lies in the range [1, N], the array size is (N-4) and no single element is repeated. So, we can understand four numbers, from 1 to N, are missing in the array. We have to find these 4 missing numbers in sorted manner.So, if the input is like A =[2, 8, 4, 13, 6, 11, 9, 5, 10], then the output will be [1, 3, 7, 12]To solve this, we will follow these steps −temp_arr := an array of size 4 with all 0sfor i in range 0 to ... Read More

Find First element in AP which is multiple of given Prime in Python

Arnab Chakraborty
Updated on 25-Aug-2020 09:13:48

42 Views

Suppose we have a first term (A) and common difference (d) of an AP series, and we also have a prime number P, we have to find the position of the first element in the given AP which is the a multiple of the given prime number P.So, if the input is like A = 3, D = 4, P = 5, then the output will be 3 as fourth term of the given AP is a multiple of the prime number 5. So, first term = 3, second term = 3+4 = 7, third term = 3+2*4 = 11 ... Read More

Find element position in given monotonic sequence in Python

Arnab Chakraborty
Updated on 25-Aug-2020 09:11:49

175 Views

Suppose we have a number l and a monotonic increasing sequence f(m), where f(m) = am + bm [log2(m)] + cm^3 and (a = 1, 2, 3, …), (b = 1, 2, 3, …), (c = 0, 1, 2, 3, …)Here [log2(m)] is the log to the base 2 and round the value down. so, 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. and so, onwe have to find the value m such that f(m) = l, if l ... Read More

Find Duplicates of array using bit array in Python

Arnab Chakraborty
Updated on 25-Aug-2020 09:09:37

137 Views

Suppose we have an array of n different numbers; n can be 32, 000 at max. The array may have duplicate entries and we do not know what is the value of n. Now if we have only 4-Kilobytes of memory, how would display all duplicates in the array?So, if the input is like [2, 6, 2, 11, 13, 11], then the output will be [2, 11] as 2 and 11 appear more than once in given array.To solve this, we will follow these steps −Create one byte-array type data structure bit_arr, it has following methodsDefine constructor This will take ... Read More

Find distinct elements common to all rows of a matrix in Python

Arnab Chakraborty
Updated on 25-Aug-2020 09:07:56

164 Views

Suppose we have a square matrix of order m x m; we have to find all the distinct elements common to all rows of the given matrix.So, if the input is like13215417153243615215412152643221942215then the output will be [2, 4, 15]To solve this, we will follow these steps −Define a function sortRows() . This will take matrixn := count of rowsfor i in range 0 to n, dosort the list matrix[i]In the main method, do the following −n := count of rowssortRows(matrix)current_idx := a list of size n, fill with 0for i in range 0 to n, docurrent_idx[i] := 0f := 0while ... Read More

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

Arnab Chakraborty
Updated on 25-Aug-2020 09:04:02

168 Views

Suppose we have two arrays A and B of n integers, now consider an array C, where the i-th number will be d*A[i] + B[i] and here d is any arbitrary real number. We have to find d such that array C has maximum number of zeros. Also return the number of zeros.So, if the input is like A = [15, 40, 45] and B = [4, 5, 6], then the output will be d = -0.266666, number of zeros will be 1To solve this, we will follow these steps −n := size of Amy_map := a new mapcount := ... Read More

Find combined mean and variance of two series in Python

Arnab Chakraborty
Updated on 25-Aug-2020 09:01:19

582 Views

Suppose we have two different series A1 and A2 of size b and a respectively. We have to find the mean and variance of combined series.So, if the input is like A1 = [24, 46, 35, 79, 13, 77, 35] and A2 = [66, 68, 35, 24, 46], then the output will be Mean = [44.1429, 47.8], sd = [548.694, 294.56], combined mean = 45.6667, d1_square = 2.322, d2_square = 4.5511, combined_var = 446.056To solve this, we will follow these steps −Define a function mean() . This will take arrreturn average of arr elementsDefine a function sd() . This will ... Read More

Find the minimum sum of distance to A and B from any integer point in a ring of size N in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:40:14

84 Views

Suppose we have a ring, which is made of few numbers from 1 to N. We also have tow numbers A and B. Now, we can stand at any place (say x) and perform the count operation with respect of the total sum of the distance (say Z = distance from X to A + distance from X to B). We have to select X such that Z is minimized. At the end return the value of Z. We have to keep in mind that X will not be same as A and B.So, if the input is like N ... Read More

Find the minimum positive integer such that it is divisible by A and sum of its digits is equal to B in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:37:36

189 Views

Suppose we have two numbers A and B, we have to find the minimum positive number M so that M is divisible by A and the sum of the digits of M is same as B. So, if there is no such result, then return -1.So, if the input is like A = 50, B = 2, then the output will be 200 as this is divisible by 50 and sum of its digit = 2 + 0 + 0 = 2.To solve this, we will follow these steps −Define one element type container, that contains two numbers a and ... Read More

Find the minimum of maximum length of a jump required to reach the last island in exactly k jumps in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:33:21

138 Views

Suppose we have an array A of numbers, in A the i-th number is the position where an island is present, and another integer k is given (1 ≤ k < N). Now, a person is standing on the 0-th island and has to reach the last island, by jumping from one island to another in exactly k jumps, we have to find the minimum of the maximum length of a jump a person will make in his/her journey. We have to keep in mind that the position of all the islands are given in ascending order.So, if the input ... Read More

Advertisements