Programming Articles

Page 465 of 2547

Check whether the point (x, y) lies on a given line in Python

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

To check whether a point (x, y) lies on a given line, we need to verify if the point satisfies the line equation. For a line in the form y = mx + b, where m is the slope and b is the y-intercept, we substitute the point's coordinates into the equation. If the equation holds true (left side equals right side), then the point lies on the line. Otherwise, it doesn't. Problem Example Given a line with slope m = 3 and y-intercept b = 5, we need to check if point (6, 23) lies on ...

Read More

Check whether the number formed by concatenating two numbers is a perfect square or not in Python

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

Sometimes we need to check if concatenating two numbers creates a perfect square. A perfect square is a number that can be expressed as the product of an integer with itself (like 16 = 4²). So, if the input is like x = 2 and y = 89, then the output will be True as after concatenating the number will be 289 which is 17². Algorithm To solve this problem, we will follow these steps − Convert both numbers to strings Concatenate the strings and convert back ...

Read More

Check whether the number can be made perfect square after adding 1 in Python

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

Given a number n, we need to check whether adding 1 to it results in a perfect square. A perfect square is a number that can be expressed as the product of an integer with itself (like 4 = 2², 9 = 3², 16 = 4²). For example, if n = 288, then n + 1 = 289, and 289 = 17², so the answer is True. Algorithm To solve this problem, we follow these steps ? Calculate res_num = n + 1 Find sqrt_val = integer part of square root of res_num If sqrt_val ...

Read More

Check whether the length of given linked list is Even or Odd in Python

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

Determining whether a linked list has an even or odd number of nodes is a common programming problem. The most efficient approach uses the two-pointer technique to traverse the list in a single pass without counting all nodes. Algorithm Explanation The algorithm uses a single pointer that moves two steps at a time: Start from the head and jump two nodes forward in each iteration If the pointer becomes None, the list has an even number of nodes If the pointer reaches the last node (next is None), the list has an odd number of nodes ...

Read More

Check whether the given numbers are Cousin prime or not in Python

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

Two numbers are called cousin primes when both are prime numbers and their absolute difference is exactly 4. This is different from twin primes (difference of 2) and sexy primes (difference of 6). For example, (7, 11) are cousin primes because both are prime and |11 - 7| = 4. Similarly, (19, 23) are cousin primes. Algorithm To check if two numbers are cousin primes ? Check if the absolute difference between the numbers is exactly 4 Verify that both numbers are prime Return True only if both conditions are satisfied Implementation ...

Read More

Check whether the given number is Wagstaff prime or not in Python

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

A Wagstaff prime is a prime number that can be expressed in the form (2q + 1)/3, where q is an odd prime number. These numbers are named after mathematician Samuel S. Wagstaff Jr. Wagstaff Prime Formula W = (2^q + 1) / 3 where q is an odd prime Example For n = 683, we can verify it's a Wagstaff prime because 683 = (211 + 1)/3, where q = 11 is an odd prime. Algorithm To check if a number is a ...

Read More

Check whether the given number is Euclid Number or not in Python

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

A Euclid number is an integer that can be represented as the product of the first n prime numbers plus 1. In mathematical terms, a Euclid number follows the formula: En = Pn + 1 where Pn is the product of the first n prime numbers. For example, 211 is a Euclid number because it can be expressed as (2×3×5×7) + 1 = 210 + 1 = 211. Algorithm To check if a number is a Euclid number, we need to ? Generate all prime numbers up to a reasonable limit using the Sieve ...

Read More

Check whether the frequencies of all the characters in a string are prime or not in Python

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

Sometimes we need to check whether the frequencies of all characters in a string are prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. So, if the input is like s = "apuuppa", then the output will be True as there are two 'a's, three 'p's and two 'u's. Since 2 and 3 are prime numbers, all character frequencies are prime. Algorithm To solve this problem, we will follow these steps − Create a frequency map containing all characters and their counts ...

Read More

Check whether the Average Character of the String is present or not in Python

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

When working with strings in Python, you might need to find the "average character" based on ASCII values. This involves calculating the average of all character ASCII values and determining if that average corresponds to an actual character in the string. The average character is found by taking the floor of the average ASCII values of all characters in the string. If this average ASCII value corresponds to a character present in the original string, we return that character. Example Let's say we have the string s = "pqrst". The ASCII values are: p = ...

Read More

Check whether sum of digits at odd places of a number is divisible by K in Python

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

In this problem, we need to check whether the sum of digits at odd positions (counting from right to left) of a number is divisible by a given value k. The positions are counted starting from 1. So, if the input is like n = 2416 and k = 5, then the output will be True. The digits at odd positions from right to left are: position 1 (digit 6) and position 3 (digit 4). Their sum is 4 + 6 = 10, which is divisible by 5. Algorithm To solve this problem, we will follow these ...

Read More
Showing 4641–4650 of 25,466 articles
« Prev 1 463 464 465 466 467 2547 Next »
Advertisements