Server Side Programming Articles

Page 467 of 2109

Check if array contains contiguous integers with duplicates allowed in Python

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

A sequence of numbers is said to be contiguous if the numbers can be arranged in such a way that each number follows the previous one without any gaps. For example, [11, 12, 13, 14] is a contiguous sequence because there are no missing numbers between the smallest and largest values. In this article, we need to check if an array contains such contiguous integers, even when duplicates are present. For instance, [11, 12, 13, 13, 14] should still be considered contiguous because the unique numbers are [11, 12, 13, 14], which form a proper sequence without breaks. ...

Read More

Check if any permutation of N equals any power of K in Python

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

This problem asks us to determine if any permutation of the digits of number n equals some power of number m. For example, given n = 7182 and m = 12, we find that 1728 (a permutation of 7182) equals 12³. Approach We'll generate all powers of m within our range, then check if any power has the same digit frequency as n using sets for comparison ? Helper Function to Check Digit Permutation First, we create a function to check if two numbers have the same digits ? def check_power(n, m): temp_arr_1 = [] ...

Read More

Check if array can be sorted with one swap in Python

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

Sorting is a task used to organize numbers in increasing order. Usually, we use sorting algorithms to do this, but in most cases, the array is almost sorted, with only two or three numbers in the wrong position. In such scenarios, instead of sorting the entire array, we can check if swapping just one pair of elements will make the entire array sorted. Problem Definition Given an array with distinct integers, we need to find if it can become completely sorted by swapping only one pair of elements. We are not performing the swap, just checking if ...

Read More

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 299 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 787 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
Showing 4661–4670 of 21,090 articles
« Prev 1 465 466 467 468 469 2109 Next »
Advertisements