Server Side Programming Articles

Page 465 of 2109

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 304 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 361 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 425 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 718 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 318 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 419 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

Rotate Matrix in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 7K+ Views

Rotating a matrix in Python can be done using various approaches. The most common method is the Transpose and Reverse technique, which converts rows to columns and then reverses each row to achieve a 90-degree clockwise rotation. Original Matrix Let's consider a 3×3 matrix that we want to rotate 90 degrees clockwise ? 1 5 7 9 6 3 2 1 3 Using Transpose and Reverse This method is efficient and involves two main steps ? Transpose the matrix ? Convert rows to columns and ...

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 371 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 351 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

Check if Decimal representation of an Octal number is divisible by 7 in Python

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

We need to check whether the decimal representation of a given octal number is divisible by 7. An octal number uses base 8, so we convert it to decimal and then check divisibility. For example, if the octal number is 61, its decimal representation is 6×8¹ + 1×8⁰ = 48 + 1 = 49, which is divisible by 7. Algorithm To solve this problem, we follow these steps − Initialize sum = 0 While the octal number is non-zero: ...

Read More
Showing 4641–4650 of 21,090 articles
« Prev 1 463 464 465 466 467 2109 Next »
Advertisements