Programming Articles

Page 467 of 2547

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 157 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

Check if the given array can be reduced to zeros with the given operation performed given number of times in Python

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

We need to check if an array can be reduced to all zeros by performing a specific operation exactly k times. The operation subtracts the smallest non-zero element from all non-zero elements in the array. Understanding the Problem Let's break down how the operation works ? Operation: Find the smallest non-zero element and subtract it from all non-zero elements Goal: Reduce all elements to zero in exactly k operations Key insight: Each operation eliminates one distinct value from the array Example Walkthrough Consider the array [2, 2, 3, 5] with k = 3 ...

Read More

Check if the frequency of all the digits in a number is same in Python

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

A number is considered balanced when the frequency of all its digits is the same. For example, in the number 562256, each digit (5, 6, and 2) appears exactly 2 times, making it a balanced number. In this article, we'll explore different methods to check if a number is balanced in Python. Using Dictionary to Count Frequencies We can convert the number to a string and use a dictionary to count the frequency of each digit ? from collections import defaultdict def is_balanced(num): number = str(num) ...

Read More

Check if the first and last digit of the smallest number forms a prime in Python

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

Given an array of digits, we need to find the smallest possible number from those digits, then check if numbers formed by the first and last digits are prime. This involves sorting digits to create the minimum number and testing primality. Problem Overview For example, if we have digits = [5, 2, 1, 7], the smallest number is 1257. We then form numbers using first and last digits: 17 and 71, and check if they are prime. Algorithm Steps The solution follows these steps − Count frequency of each digit (0-9) Build the smallest ...

Read More
Showing 4661–4670 of 25,466 articles
« Prev 1 465 466 467 468 469 2547 Next »
Advertisements