Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 62 of 377

Check if number is palindrome or not in Octal in Python

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

A palindrome is a number that reads the same forwards and backwards. In this problem, we need to check if a given number is a palindrome in its octal representation. If the input number is already in octal format (all digits < 8), we check it directly. If it's in decimal format, we first convert it to octal, then check if the result is a palindrome. For example, if the input is 178, it contains digit 8 which is not valid in octal, so it's treated as decimal. Converting 178 to octal gives 262, which is a palindrome. ...

Read More

Check if one of the numbers is one's complement of the other in Python

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

Suppose we have two numbers x and y. We have to check whether one of these two numbers is 1's complement of the other or not. We all know the 1's complement of a binary number is flipping all bits from 0 to 1 or 1 to 0. So, if the input is like x = 9, y = 6, then the output will be True as the binary representations are x = 1001 and y = 0110 which are complement of each other. Algorithm To solve this, we will follow these steps − ...

Read More

Check if number can be displayed using seven segment led in Python

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

Suppose we have a number n and a constraint c. We need to check whether n can be displayed using 7-segment displays with at most c LEDs. Each digit requires a different number of LED segments to be illuminated. For example, if the input is n = 315 and c = 17, the output will be True since 315 needs 12 LEDs (3 needs 5, 1 needs 2, 5 needs 5) and we have 17 available. Seven Segment Display LED Count: ...

Read More

Check if N is Strong Prime in Python

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

A strong prime is a prime number that is greater than the arithmetic mean of its nearest prime neighbors. In other words, if we have a prime number p, and its previous prime is p1 and next prime is p2, then p is strong if p > (p1 + p2) / 2. For example, if we have num = 37, the nearest prime numbers are 31 and 41. The average is (31 + 41) / 2 = 36, and since 37 > 36, it is a strong prime. Algorithm Steps To check if a number is a ...

Read More

Check if n is divisible by power of 2 without using arithmetic operators in Python

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

When we need to check if a number is divisible by a power of 2 without using arithmetic operators, we can use bitwise operations. This approach leverages the binary representation of numbers and bit manipulation. Problem Understanding Given two numbers x and n, we need to check whether x is divisible by 2n without using division, modulo, or other arithmetic operators. For example, if x = 32 and n = 5, we check if 32 is divisible by 25 = 32. Algorithm The key insight is that a number is divisible by 2n if and only ...

Read More

Check if N is divisible by a number which is composed of the digits from the set {A, B} in Python

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

Given a number n and two digits a and b, we need to check if we can form a number using only digits a and b that divides n. This problem can be solved using recursion by generating all possible combinations of numbers formed using the given digits. For example, if n = 115, a = 3, b = 2, then the output will be True because 115 is divisible by 23, which is made of digits 2 and 3. Algorithm Steps To solve this problem, we will follow these steps − ...

Read More

Check if N is a Factorial Prime in Python

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

A factorial prime is a prime number that is either one less than or one more than a factorial of any positive integer. For example, 719 is a factorial prime because 719 = 6! - 1 = 720 - 1, where 6! = 720. In this article, we'll learn how to check if a given number N is a factorial prime in Python. What is a Factorial Prime? A factorial prime has the form n! ± 1, where: n! + 1 (one more than factorial) n! - 1 (one less than factorial) The ...

Read More

Check if N can be represented as sum of integers chosen from set {A, B} in Python

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

Sometimes we need to check if a target number can be represented as a sum of two given integers A and B, where we can use each integer any number of times. This is a classic dynamic programming problem that can be solved using memoization. Problem Understanding Given a target number and two integers A and B, we need to determine if we can express the target as a linear combination of A and B with non-negative coefficients. For example, if target = 26, A = 5, and B = 7, we can achieve this as 26 = ...

Read More

Check if moves in a stack or queue are possible or nots in Python

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

Stack and queue operations follow a specific order where elements must be pushed before they can be popped. Given a binary list where 1 represents a push operation and 0 represents a pop operation, we need to validate if the sequence of operations is possible without attempting to pop from an empty structure. Problem Understanding The key insight is that at any point during the operations, the number of pop operations cannot exceed the number of push operations. If we encounter more pops than pushes, we're trying to remove elements from an empty stack or queue, which is ...

Read More

Check if mirror image of a number is same if displayed in seven segment displays in Python

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

In seven-segment displays, only certain digits look the same when mirrored horizontally. We need to check if a number appears identical to its mirror image when displayed on such a device. The digits that look the same when mirrored in seven-segment displays are 0, 1, and 8. Other digits like 2, 3, 4, 5, 6, 7, 9 don't have symmetric mirror images. Understanding Seven-Segment Mirror Images .segment { fill: #333; stroke: none; } .text { font-family: ...

Read More
Showing 611–620 of 3,768 articles
« Prev 1 60 61 62 63 64 377 Next »
Advertisements