Programming Articles

Page 546 of 2547

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 274 Views

Finding missing numbers in an array is a common programming problem. When we have an array of distinct numbers from range [1, N] with size (N-4), exactly four numbers are missing. This problem can be solved efficiently using array manipulation techniques. Problem Understanding Given an array of distinct numbers where: Each number lies in range [1, N] Array size is (N-4) No element is repeated We need to find 4 missing numbers in sorted order For example, if A = [2, 8, 4, 13, 6, 11, 9, 5, 10], then N = 13 and the ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 147 Views

In this problem, we need to find the position of the first element in an Arithmetic Progression (AP) that is divisible by a given prime number. Given the first term A, common difference D, and prime number P, we use modular arithmetic to efficiently find this position. For example, if A = 3, D = 4, P = 5, the AP terms are: 3, 7, 11, 15, 19... The fourth term (15) is the first multiple of 5, so the answer is 3 (0-indexed position). Algorithm Approach The solution uses Fermat's Little Theorem and modular exponentiation. For ...

Read More

Find element position in given monotonic sequence in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 336 Views

When working with monotonic sequences, we often need to find the position where a specific value occurs. This problem involves a monotonic increasing sequence defined by the function f(m) = am + bm[log₂(m)] + cm³, where [log₂(m)] represents the floor of log base 2. Understanding the Formula The sequence function f(m) = am + bm[log₂(m)] + cm³ contains three components: Linear term: am (where a = 1, 2, 3, ...) Logarithmic term: bm[log₂(m)] (where b = 1, 2, 3, ...) Cubic term: cm³ (where c = 0, 1, 2, 3, ...) The floor logarithm ...

Read More

Find Duplicates of array using bit array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 249 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. How Bit Array Works A bit array uses individual bits to track whether a number has been seen ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 371 Views

Finding distinct elements common to all rows of a matrix is a useful operation in data analysis. We need to identify elements that appear in every row of the matrix, regardless of their position. So, if the input matrix is: 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 Then the output will be [2, 4, 15], as these elements appear in all rows. Using Set ...

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
Arnab Chakraborty
Updated on 25-Mar-2026 298 Views

Given two arrays A and B of n integers, we need to create array C where C[i] = d*A[i] + B[i] and d is any real number. Our goal is to find the value of d that maximizes the number of zeros in array C. For C[i] to be zero, we need d*A[i] + B[i] = 0, which gives us d = -B[i]/A[i] (when A[i] ≠ 0). Algorithm The approach is to ? Calculate possible values of d for each element where A[i] ≠ 0 Count frequency of each d value using a dictionary Handle ...

Read More

Find combined mean and variance of two series in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 931 Views

When working with two separate data series, you often need to find the combined mean and combined variance of the merged dataset. This is useful in statistics when combining samples from different populations or datasets. The combined mean is calculated as a weighted average of individual means, while the combined variance uses the formula that accounts for both individual variances and the differences between individual means and the combined mean. Mathematical Formula For two series A1 and A2 with sizes n and m respectively: Combined Mean: (n × mean₁ + m × mean₂) / (n ...

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
Arnab Chakraborty
Updated on 25-Mar-2026 206 Views

We need to find the minimum sum of distances from any integer point X to two given points A and B on a ring of size N. The goal is to position X such that the total distance (distance from X to A + distance from X to B) is minimized, where X cannot be the same as A or B. In a ring structure, we can move in two directions: clockwise and counter-clockwise. The optimal position for X will depend on which path gives us the minimum total distance. Example Walkthrough If N = 30, A ...

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
Arnab Chakraborty
Updated on 25-Mar-2026 344 Views

Given two numbers A and B, we need to find the minimum positive integer M such that M is divisible by A and the sum of its digits equals B. If no such number exists, return -1. For example, if A = 50 and B = 2, the output will be 200 because 200 is divisible by 50 and the sum of its digits (2 + 0 + 0 = 2) equals B. Approach We'll use a breadth-first search (BFS) approach with the following strategy ? Use a queue to explore numbers digit by digit ...

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
Arnab Chakraborty
Updated on 25-Mar-2026 265 Views

Suppose we have an array A of numbers, where the i-th number represents the position of an island. Given another integer k (1 ≤ k < N), a person standing on the 0-th island must reach the last island in exactly k jumps. We need to find the minimum of the maximum jump length required for this journey. All island positions are given in ascending order. For example, if A = [7, 20, 41, 48] and k = 2, the output will be 28. There are two possible paths: Path 1: 7 → 20 → 48 (jumps: ...

Read More
Showing 5451–5460 of 25,466 articles
« Prev 1 544 545 546 547 548 2547 Next »
Advertisements