Server Side Programming Articles

Page 463 of 2109

Check whether it is possible to make both arrays equal by modifying a single element in Python

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

Suppose we have two arrays nums1 and nums2 and another value k. We have to check whether both arrays can be made equal by modifying any one element from nums1 in the following way (only once): We can add any value from the range [-k, k] to any element of nums1. So, if the input is like nums1 = [5, 7, 11], nums2 = [5, 5, 11], k = 8, then the output will be True as we can add -2 (in range [-8, 8]) with nums1[1] to make it 5 then it will be same as nums2. ...

Read More

Check whether given three numbers are adjacent primes in Python

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

Adjacent primes are consecutive prime numbers with no other prime numbers between them. For example, 5, 7, and 11 are adjacent primes because 7 is the next prime after 5, and 11 is the next prime after 7. So, if the input is like nums = [5, 7, 11], then the output will be True since these are three consecutive primes. Algorithm To solve this problem, we will follow these steps: Check if all three numbers are prime Verify that the second number is the next prime after the first Verify that the third number ...

Read More

Check whether given string can be generated after concatenating given strings in Python

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

In Python, we often need to check whether a given string can be formed by concatenating two other strings in either order. This problem involves verifying if string r equals s + t or t + s. For example, if we have strings s = "world", t = "hello", and r = "helloworld", we need to check if r can be formed by concatenating s and t in either order. Algorithm To solve this problem, we follow these steps ? First, check if the length of r equals the sum of lengths of s and ...

Read More

Check whether given floating point number is even or odd in Python

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

Determining whether a floating-point number is even or odd requires a different approach than integers. We cannot simply check the last digit by dividing by 2, since floating-point numbers have decimal parts that need special handling. The key insight is to find the first significant digit from right to left (ignoring trailing zeros after the decimal point) and check if that digit is even or odd. Example For the number 200.290, we ignore the trailing zero and check the digit 9, which makes the number odd. Algorithm The approach involves these steps ? ...

Read More

Check whether given degrees of vertices represent a Graph or Tree in Python

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

In graph theory, we can determine whether a given sequence of vertex degrees represents a tree or a general graph using the Handshaking Lemma. A tree with n vertices always has exactly n-1 edges, which gives us a mathematical condition to check. Understanding the Theory According to the Handshaking Lemma, the sum of all vertex degrees equals twice the number of edges. For a tree with n vertices: Number of edges = n - 1 Sum of degrees = 2 × (n - 1) If this condition is satisfied, the degree sequence can represent ...

Read More

Check whether given circle resides in boundary maintained by two other circles in Python

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

Sometimes we need to check whether a given circle lies within the boundary formed by two concentric circles. This is a common geometric problem that can be solved using distance calculations and boundary conditions. Problem Understanding We have two concentric circles with radii r1 (outer) and r2 (inner), both centered at the origin. Given another circle with center at coordinates coord and radius r, we need to determine if this circle fits completely within the annular region (ring-shaped area) between the two concentric circles. ...

Read More

Check if the given number K is enough to reach the end of an array in Python

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

We need to traverse an array and check if we can reach the end with a given number k. The rules are: decrement k by 1 for non-prime numbers, and refill k to its original value when encountering prime numbers. If k becomes 0 or negative and the next element is non-prime, we cannot proceed. Problem Analysis Let's trace through the example: nums = [8, 5, 6, 7, 8], k = 2 nums[0] = 8 (not prime) → k = 1 nums[1] = 5 (prime) → k = 2 (refilled) nums[2] = 6 (not prime) → ...

Read More

Check if the given number is Ore number or not in Python

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

An ore number (or harmonic divisor number) is a positive integer where the harmonic mean of its divisors is an integer. The harmonic mean of divisors is calculated as the number of divisors divided by the sum of reciprocals of all divisors. For example, 28 has divisors [1, 2, 4, 7, 14, 28]. The harmonic mean is 6 ÷ (1/1 + 1/2 + 1/4 + 1/7 + 1/14 + 1/28) = 3, which is an integer. Harmonic Mean Formula H = n / (1/d₁ + 1/d₂ + ... + 1/dₙ) For ...

Read More

Check if the given decimal number has 0 and 1 digits only in Python

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

Sometimes we need to check if a decimal number contains only binary digits (0 and 1). This is useful for validating binary representations or checking if a number can be interpreted as a binary string. So, if the input is like num = 101101, then the output will be True since it contains only 0s and 1s. Algorithm To solve this, we will follow these steps − Extract all digits from the number into a set Remove 0 and 1 from the digits set If the set is empty after removal, return True Otherwise, return ...

Read More

Check if the given array contains all the divisors of some integer in Python

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

Sometimes we need to verify if a given array contains all the divisors of some integer. This problem involves finding divisors of the maximum element and comparing them with the array elements. So, if the input is like nums = [1, 2, 3, 4, 6, 8, 12, 24], then the output will be True as these are all the divisors of 24. Algorithm To solve this, we will follow these steps − Find the maximum element in the array (potential number whose divisors we're checking) Generate all ...

Read More
Showing 4621–4630 of 21,090 articles
« Prev 1 461 462 463 464 465 2109 Next »
Advertisements