Programming Articles

Page 466 of 2547

Check whether second string can be formed from characters of first string in Python

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

Suppose we have two strings s and t. We have to check whether t can be formed using characters of s or not. So, if the input is like s = "owleh" t = "hello", then the output will be True. Algorithm To solve this, we will follow these steps ? freq := a map containing all characters and their frequencies for i in range 0 to size of t - 1, do ...

Read More

Check if a number can be expressed as a^b in Python

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

Sometimes we need to check if a number can be expressed as a power of another number, i.e., whether we can write it as a^b where both a and b are positive integers. So, if the input is like 125, then the output will be True as 125 = 5^3, so a = 5 and b = 3. Algorithm To solve this, we will follow these steps − If num is same as 1, then return True (since 1 = 1^1) For each potential base i from 2 to √num: Calculate val = log(num) ...

Read More

Check whether product of integers from a to b is positive, negative or zero in Python

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

When we need to determine the sign of a product of integers in a range [a, b], we don't need to calculate the actual product. Instead, we can use mathematical rules to determine if the result will be positive, negative, or zero. So, if the input is like a = -8, b = -2, then the output will be Negative, as the values in that range are [-8, -7, -6, -5, -4, -3, -2], and the product is -40320 which is negative. Algorithm To solve this efficiently, we follow these steps: If both a and ...

Read More

Check whether product of digits at even places of a number is divisible by K in Python

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

Sometimes we need to check if the product of digits at even positions (counting from right to left) of a number is divisible by another number. In this problem, the rightmost digit is at position 1, the next digit is at position 2, and so on. For example, in the number 59361, the digits at even positions are 6 (position 2), 9 (position 4), making the product 6 × 9 = 54. If we need to check divisibility by 3, then 54 ÷ 3 = 18, so it's divisible. Algorithm To solve this problem, we follow these ...

Read More

Check whether product of \'n\' numbers is even or odd in Python

Akshitha Mote
Akshitha Mote
Updated on 25-Mar-2026 682 Views

In this article, we explore different methods to check whether the product of n numbers is even or odd. A number that is divisible by 2 is known as an even number, otherwise it is an odd number. For example, 14 and 12 are two even numbers, their product 168 is even. Numbers 9 and 5 are odd, their product 45 is odd. Consider one even number 2 and one odd number 3 − their product 6 is even. Mathematical Facts Understanding these mathematical rules helps us determine if a product is even or odd − ...

Read More

Check whether N is a Dihedral Prime Number or not in Python

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

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 More

Check whether K-th bit is set or nots in Python

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

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 More

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 283 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
Showing 4651–4660 of 25,466 articles
« Prev 1 464 465 466 467 468 2547 Next »
Advertisements