Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 6 of 377

Program to find out the minimum value from sum of node values of sub-trees in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 230 Views

Suppose we have a tree with nodes numbered 1 to n, where each node contains an integer value. When we remove any edge from the tree, it splits into two sub-trees. Our goal is to find the minimum possible difference between the sums of node values in these two sub-trees. The tree is given as a collection of edges, and the node values are provided in a list. Problem Understanding If the input is n = 6, edge_list = [[1, 2], [1, 3], [2, 4], [3, 5], [3, 6]], values = [15, 25, 15, 55, 15, 65], ...

Read More

Program to find out the XOR values of specific elements from a generated list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 235 Views

Sometimes we need to generate a special sequence by removing numbers with consecutive 1s in their binary representation, then compute XOR values from specific positions. This involves generating a Zeckendorf-like sequence and performing bitwise operations. Problem Understanding Given a list of natural numbers, we remove all numbers containing two consecutive 1s in their binary representation to create list Z. Then we find the XOR of elements at specified indices from Z. For example, if input_list = [3, 4, 5], we need elements at indices 3, 4, and 5 from Z, which are 4, 5, and 8. So ...

Read More

Program to find out the scalar products of vectors generated from an infinite sequence in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 222 Views

We need to find scalar products of vectors generated from an infinite sequence. Given three integers c, m, and n, we generate a sequence where the first value is 0, second is c, and subsequent values follow ki = (ki-2 + ki-1) mod m. From this sequence, we create n vectors using consecutive pairs and calculate scalar products between all vector pairs. Problem Breakdown Let's understand with example: c=5, m=6, n=4 − Generate sequence: [0, 5, 5, 4, 3, 1, 4, 5, 3, 2] Create vectors from consecutive pairs starting from index 2: (5, 4), (3, ...

Read More

Program to find out the sum of the number of divisor of the divisors in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 364 Views

This problem involves calculating the sum of divisor counts for all divisors of a specially constructed number. Given integers m and a, we construct n = p1(a + 1) × p2(a + 2) × ... × pm(a + m), where pi is the i-th prime number. We need to find the sum of f(x) values for all divisors of n, where f(x) represents the number of divisors of x. Problem Understanding For m = 2 and a = 1: n = 22 × 33 = 4 × 27 = 108 Divisors of 108: 1, 2, 3, ...

Read More

Program to find out the value of a given equation in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 1K+ Views

Finding the value of the equation ((ab)(cd)) mod n requires careful handling of very large numbers. This problem involves nested exponentiation, which can quickly produce numbers too large for direct computation. Problem Statement Given five integers a, b, c, d, and n, we need to calculate ((ab)(cd)) mod n efficiently. Example For a = 2, b = 3, c = 2, d = 4, n = 10: 2^3 = 8 2^4 = 16 8^16 = 281474976710656 281474976710656 mod 10 = 6 Solution Approach We use Euler's theorem and the Carmichael function ...

Read More

Program to find out the length of the substring where two times the number of zeroes in substring is lesser than or equal to three times the number of ones in the substring in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 253 Views

Sometimes we need to find the maximum length substring where the number of zeros and ones satisfy a specific condition. This problem involves finding a substring in a repeated string where 2 × (zeros) ≤ 3 × (ones). Problem Understanding Given a string and integer k, we repeat the string k times to create a new string. We need to find the longest substring where the condition 2 * zeros ≤ 3 * ones holds true. Example If k = 2 and input_str = '0101011', the repeated string becomes '01010110101011' (length 14). This entire string satisfies ...

Read More

Program to find out the value of a power of 2 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 467 Views

Finding the value of 2^(2^p) mod q is a common mathematical problem that involves computing very large powers efficiently. Python's built-in pow() function provides an elegant solution using modular exponentiation. Problem Understanding Given two integers p and q, we need to calculate 2^(2^p) mod q. For example, if p = 5 and q = 6: First calculate 2^p = 2^5 = 32 Then calculate 2^32 mod 6 The result is 4 Solution Approach We use Python's pow(base, exponent, modulus) function which efficiently computes (base^exponent) ...

Read More

Program to find out the number of special numbers in a given range in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

A special number is a positive integer that either has only 1 digit, or if it has multiple digits, it must be divisible by its digit count and the quotient must also be a special number. Let's find how many special numbers exist within a given range. Understanding Special Numbers The definition of special numbers works recursively: Single-digit numbers (1-9) are always special Multi-digit numbers are special if: number ÷ digit_count = special_number For example: 12 ÷ 2 = 6 (6 is special, so 12 is special) Example For the range [5, 30], ...

Read More

Program to find out the number of consecutive elements in a matrix whose gcd is greater than 1 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 242 Views

Suppose we are given a matrix that contains n rows and m columns. We have to find out the largest number of consecutive elements in the matrix where the gcd of the elements is greater than 1. The consecutive elements can either lie horizontally or vertically in the matrix. So, if the input is like ? 3 7 ...

Read More

Program to find out the largest sum value of a BST in a given binary tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 259 Views

Suppose we are provided a binary tree. We have to find out if there exist binary search trees (BST) in the subtrees of it and find out the sum of the largest BST. To find out the sum, we add the values of each node in that BST. We return the sum value as output. So, if the input is like ? then the output will be 12. The BST in the given binary tree is ? sum of the nodes = 12. Algorithm To solve this, we will follow ...

Read More
Showing 51–60 of 3,768 articles
« Prev 1 4 5 6 7 8 377 Next »
Advertisements