Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Arnab Chakraborty
Page 70 of 377
Check whether N is a Dihedral Prime Number or not in Python
A Dihedral Prime Number is a number that remains prime when viewed on a 7-segment display in normal orientation and when rotated 180 degrees (upside down). The number must contain only digits that look the same when rotated: 0, 1, 2, 5, and 8. For example, if we have n = 1181, it appears as 1881 when rotated upside down (since 2 becomes 5 and 5 becomes 2), and both numbers are prime. Normal: 1181 Rotate 180° Upside down: ...
Read MoreCheck whether K-th bit is set or nots in Python
Suppose we have a number n and another value k. We have to check whether the k-th bit in n is set (1) or not. The value of k is considered from the right-hand side (1-indexed). So, if the input is like n = 23, k = 3, then the output will be True as binary form of 23 is 10111, so the 3rd bit from the right is 1 (set). Algorithm To solve this, we will follow these steps ? Shift n right by (k - 1) positions to bring the ...
Read MoreCheck whether it is possible to make both arrays equal by modifying a single element in Python
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 MoreCheck whether given three numbers are adjacent primes in Python
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 MoreCheck whether given string can be generated after concatenating given strings in Python
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 MoreCheck whether given floating point number is even or odd in Python
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 MoreCheck whether given degrees of vertices represent a Graph or Tree in Python
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 MoreCheck whether given circle resides in boundary maintained by two other circles in Python
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 MoreCheck if the given number K is enough to reach the end of an array in Python
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 MoreCheck if the given number is Ore number or not in Python
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