Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 72 of 377

Check if the array has an element which is equal to sum of all the remaining elements in Python

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

Sometimes we need to check if an array contains an element whose value equals the sum of all other elements. This problem can be solved efficiently by calculating the total sum and using a frequency map. For example, in the array [3, 2, 10, 4, 1], the element 10 equals the sum of remaining elements: 3 + 2 + 4 + 1 = 10. Algorithm Approach The key insight is that if an element equals the sum of all other elements, then that element must be exactly half of the total array sum ? Calculate ...

Read More

Check if the array has an element which is equal to product of remaining elements in Python

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

In this problem, we need to check if an array contains an element whose value equals the product of all other elements in the array. For example, if we have nums = [3, 2, 24, 4, 1], the output will be True because 24 = (3*2*4*1). Algorithm To solve this problem, we follow these steps ? Calculate the total product of all elements For each element, check if it equals the total product divided by itself Return True if any element satisfies this ...

Read More

Check if sums of i-th row and i-th column are same in matrix in Python

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

In matrix operations, we often need to compare row and column sums. This problem asks us to check if the sum of the i-th row equals the sum of the i-th column for any row-column pair in a given matrix. Problem Understanding Given a matrix, we need to verify if there exists at least one index i where the sum of row i equals the sum of column i. For the example matrix: 2345 10642 1467 1567 Row 0 sum = 2 + 3 + ...

Read More

Check if sum of divisors of two numbers are same in Python

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

Sometimes we need to check whether two numbers have the same sum of divisors. This problem involves finding all proper divisors (excluding the number itself) of both numbers and comparing their sums. For example, if we have p = 559 and q = 703: Divisors of 559: 1, 13, 43 (sum = 57) Divisors of 703: 1, 19, 37 (sum = 57) Since both sums equal 57, the numbers have the same divisor sum. Algorithm To solve this efficiently, we'll: Create a function to calculate the sum of proper divisors Iterate only up ...

Read More

Check if suffix and prefix of a string are palindromes in Python

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

A string has palindromic prefix and suffix when both the beginning and end portions read the same forwards and backwards. This problem requires finding if a string contains at least one palindrome as a prefix and at least one palindrome as a suffix. For example, in the string "levelishighforracecar", the prefix "level" and suffix "racecar" are both palindromes. Algorithm The solution follows these steps ? Find the first palindromic prefix of length ≥ 2 If no palindromic prefix exists, return False Find any ...

Read More

Check if subarray with given product exists in an array in Python

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

When working with arrays containing positive and negative numbers, we sometimes need to check if there's a subarray whose product equals a target value. A subarray is a contiguous sequence of elements within an array. For example, given nums = [-2, -1, 1, 3, 5, 8] and k = 6, we need to find if any subarray has a product of 6. The subarray [-2, -1, 3] gives us (-2) × (-1) × 3 = 6, so the answer is True. Algorithm Approach We use Kadane's algorithm modified for products instead of sums. The key insight is ...

Read More

Check if right triangle possible from given area and hypotenuse in Python

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

Given the hypotenuse and area of a right triangle, we need to find the base and height. If it's not possible to form such a triangle, we return False. So, if the input is like hypo = 10, area = 24, then the output will be (6, 8). Algorithm To solve this, we will follow these steps − Calculate the maximum possible area for the given hypotenuse If the required area exceeds the maximum, return False Use binary search to find the base ...

Read More

Check if reversing a sub array make the array sorted in Python

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

Sometimes we need to check if an array can be sorted by reversing exactly one sub-array. This problem involves finding a decreasing sequence and verifying if reversing it would make the entire array sorted. Problem Understanding Given an array with unique elements, we need to determine if reversing one sub-array will make the entire array sorted. If the array is already sorted, return True. For example, in [4, 6, 27, 25, 15, 9, 37, 42], reversing the sub-array [27, 25, 15, 9] gives us [4, 6, 9, 15, 25, 27, 37, 42], which is sorted. Algorithm ...

Read More

Check if each internal node of a BST has exactly one child in Python

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

Suppose we have the preorder traversal of a binary search tree (BST). We have to check whether each internal node has only one child or not. So, if the input is like preorder = [22, 12, 13, 15, 14], then the output will be True as BST is like − 22 12 13 15 14 ...

Read More

Check if difference of areas of two squares is prime in Python

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

When working with two numbers, we can check if the difference of their square areas is a prime number. This problem uses the algebraic identity that x² - y² = (x + y)(x - y). For example, if x = 7 and y = 6, the difference is 49 - 36 = 13, which is prime. Understanding the Mathematical Approach The key insight is using the factorization: x² - y² = (x + y)(x - y) For this product to be prime, one factor must equal 1 (since a prime has only two factors: 1 and ...

Read More
Showing 711–720 of 3,768 articles
« Prev 1 70 71 72 73 74 377 Next »
Advertisements