Programming Articles

Page 471 of 2547

Check if array can be divided into two sub-arrays such that their absolute difference is Ks in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 200 Views

In this article we are going to check whether the given array can be divided into two sub-arrays in such a way that the absolute difference between the sums of these two sub-arrays is equal to the given value k. The absolute difference is nothing but the non-negative gap between two numbers, calculated as abs(sum1-sum2). In this task the split must produce two non-empty sub-arrays i.e. at least one element should be present in each part. Example Scenarios Following are the example scenarios: Scenario 1 Input: array = [3, 1, 4, 2, 2], K ...

Read More

Check if any square (with one colored cell) can be divided into two equal parts in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 268 Views

In this article, we are given a square of size n×n with exactly one cell colored. The task is to determine whether this square can be divided into two equal parts by making a single straight cut, ensuring that the colored cell lies entirely within one of the parts. Two equal parts means both splits must contain the same number of cells, which is only possible if the square side length is even. We need to check if the position of the colored cell allows such a split without being intersected by the cut. Understanding the Problem ...

Read More

Check if any permutation of a number is divisible by 3 and is Palindromic in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 300 Views

This task involves checking if any permutation of a given number's digits can form a new number that is both divisible by 3 and palindromic. A number is divisible by 3 if the sum of its digits is divisible by 3, and a number is palindromic if it reads the same forwards and backwards. Understanding the Problem For a number to be divisible by 3, the sum of its digits must be divisible by 3. For it to be palindromic, the number must read the same when reversed. We need to check if any permutation of the input ...

Read More

Check if any permutation of a large number is divisible by 8 in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 1K+ Views

A number is divisible by 8 if its last three digits form a number divisible by 8. For large numbers, checking all permutations is impractical, but we can use this divisibility rule to efficiently check if any permutation is divisible by 8. Divisibility Rule for 8 According to the divisibility rule of 8, if the last three digits of a number are divisible by 8, then the entire number is divisible by 8. We can solve this problem by checking if we can form any three-digit combination from the given digits that is divisible by 8. Examples ...

Read More

Check if any large number is divisible by 19 or not in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 490 Views

In mathematics, divisibility helps us determine whether a number can be divided by another without leaving a remainder. For example, 6 is divisible by 2 because 6/2 = 3 with no remainder. In this article, we will learn how to check if any large number is divisible by 19 in Python using the modulus operator. Why Python Handles Large Numbers Well Checking divisibility with small numbers is straightforward using standard arithmetic operations. However, when dealing with very large numbers (containing 20, 30, or even 100 digits), many programming languages encounter issues due to integer size limits. ...

Read More

Check if any large number is divisible by 17 or not in Python

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

Checking if a large number is divisible by 17 can be efficiently done using a repeated subtraction method. Instead of performing direct division, we extract the last digit and subtract it multiplied by 5 from the remaining number until we get a manageable two-digit number. The algorithm works because of the mathematical property that a number is divisible by 17 if and only if the number formed by removing the last digit and subtracting 5 times the last digit is also divisible by 17. Algorithm Steps To solve this problem, we follow these steps: While ...

Read More

Check if any interval completely overlaps the other in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 2K+ Views

In many programming problems, intervals are used to represent ranges such as time periods, numeric spans, etc. An interval is typically represented as a pair of numbers (start, end) where start ≤ end. What is Complete Interval Overlap? Complete overlap occurs when one interval fully contains another. For intervals X = (a1, a2) and Y = (b1, b2), X completely overlaps Y when a1 ≤ b1 and a2 ≥ b2. This means the entire range of Y lies within X. .label { ...

Read More

Check if any anagram of a string is palindrome or not in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 649 Views

An anagram is a rearrangement of the characters of a word or phrase to generate a new word, using all the original characters exactly once. For example, thing and night are anagrams of each other. A palindrome is a word or phrase that reads the same forward and backward, like madam or racecar. In this article, we'll check if any anagram of a string can form a palindrome. The key insight is that for a string to have a palindromic anagram, at most one character can have an odd frequency. Algorithm Logic For a palindrome to be ...

Read More

Check if an integer can be expressed as a sum of two semi-primes in Python

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

A semi-prime number is a positive integer that can be expressed as the product of exactly two prime numbers (not necessarily distinct). For example, 4 = 2×2, 6 = 2×3, and 9 = 3×3 are semi-primes. This problem asks us to determine if a given integer n can be expressed as the sum of two semi-prime numbers. Understanding Semi-Prime Numbers The first few semi-prime numbers in the range 1-100 are: 4, 6, 9, 10, 14, 15, 21, 22, 25, 26, 33, 34, 35, 38, 39, 46, 49, 51, 55, 57, 58, 62, 65, 69, 74, 77, 82, ...

Read More

Check if an encoding represents a unique binary string in Python

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

Suppose we have an array called nums that represents an encoding of a binary string of size k. We need to check whether the given encoding uniquely identifies a binary string or not. The encoding contains counts of contiguous 1s which are separated by single 0s. So, if the input is like nums = [4, 2, 3] and k = 11, then the output will be True because there is a binary string like 11110110111 of length k = 11. Understanding the Problem The encoding works as follows ? Each number in nums represents a ...

Read More
Showing 4701–4710 of 25,466 articles
« Prev 1 469 470 471 472 473 2547 Next »
Advertisements