Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Arnab Chakraborty
Page 66 of 377
Check if given number is Emirp Number or not in Python
An Emirp number is a prime number that becomes a different prime when its digits are reversed. The term "Emirp" is "prime" spelled backwards. For a number to be Emirp, it must be prime, and its reverse must also be prime (and different from the original). For example, 97 is an Emirp number because 97 is prime, and its reverse 79 is also prime. Algorithm To check if a number is Emirp, we follow these steps ? Check if the number is prime If not prime, return False Calculate the reverse of the number Check ...
Read MoreCheck if given number is a power of d where d is a power of 2 in Python
Given a number n and another value d, we need to check whether n is a power of d, where d itself is a power of 2. For example, if n = 32768 and d = 32, the result is True because 32768 = 32³. Algorithm To solve this problem, we follow these steps: First, check if n is a power of 2 using bitwise operations Count how many times we can divide n by 2 to get the power of n as base 2 Count how many times we can divide d by 2 to ...
Read MoreCheck if given four integers (or sides) make rectangle in Python
A rectangle is a quadrilateral with four right angles and two pairs of opposite sides that are equal in length. Given four integers representing sides, we need to check if they can form a rectangle. So, if the input is like sides = [10, 30, 30, 10], then the output will be True as there are two pairs of equal sides (10, 10) and (30, 30). Algorithm To solve this, we will follow these steps − If all four sides are equal, then it's a square (which is also a rectangle), ...
Read MoreCheck if given array is almost sorted (elements are at-most one position away) in Python
Suppose we have an array of numbers where all elements are unique. We need to check whether the array is almost sorted or not. An array is almost sorted when any of its elements can occur at a maximum of 1 distance away from its original position in the sorted array. For example, if we have nums = [10, 30, 20, 40], the output will be True because 10 is at its correct position and all other elements are at most one place away from their actual sorted position. Algorithm To solve this problem, we follow these ...
Read MoreCheck if frequency of each digit is less than the digit in Python
When working with digit frequency validation, we often need to check whether each digit in a number appears no more times than its own value. For example, digit 5 can appear at most 5 times, digit 3 can appear at most 3 times, and so on. So, if the input is like n = 5162569, then the output will be True as the digits and frequencies are (5, 2), (1, 1), (6, 2), (2, 1) and (9, 1). For all digits, the frequency is less than or equal to the digit value. Algorithm To solve this problem, ...
Read MoreProgram to find two pairs of numbers where difference between sum of these pairs are minimized in python
Suppose we have a list of numbers called nums and we want to select two pairs of numbers from it such that the absolute difference between the sum of these two pairs is minimized. So, if the input is like nums = [3, 4, 5, 10, 7], then the output will be 1, as we can select these pairs (3 + 7) - (4 + 5) = 1. Approach To solve this problem, we will follow these steps − Create all possible pairs and calculate their absolute differences ...
Read MoreCheck if a number is Primorial Prime or not in Python
A primorial prime is a prime number that can be expressed in the form pN# + 1 or pN# − 1, where pN# represents the primorial (product of the first N prime numbers). For example, if N=3, the primorial is 2×3×5 = 30, so 29 (30−1) and 31 (30+1) are potential primorial primes if they are also prime. Let's implement a solution to check if a given number is a primorial prime ? Algorithm Steps To solve this problem, we will − Use the Sieve of Eratosthenes to find all prime numbers up to a ...
Read MoreCheck if frequency of characters are in Recaman Series in Python
Suppose we have a lowercase string s. We have to check whether the occurrences of alphabets in s, after rearranging in any possible manner, generates the Recaman's Sequence (ignoring the first term). The Recaman's sequence is defined as follows: a₀ = 0 aₙ = aₙ₋₁ - n (if aₙ₋₁ - n > 0 and not already present in sequence) aₙ = aₙ₋₁ + n (otherwise) Some of the items of Recaman's Sequence are [0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, ...]. The first term (0) is ...
Read MoreCheck if frequency of character in one string is a factor or multiple of frequency of same character in other string in Python
When working with two strings, we sometimes need to check whether the frequency of each character in one string is a factor or multiple of the frequency of the same character in another string. This means for each common character, one frequency should be divisible by the other. So, if the input is like s = "xxyzzw" and t = "yyyxxxxzz", then the output will be True because: Frequency of 'x' in s is 2, and in t is 4 (4 is multiple of 2) Frequency of 'y' in s is 1, and in t is 3 ...
Read MoreCheck if frequency of all characters can become same by one removal in Python
Sometimes we need to check if removing exactly one character from a string can make all remaining characters have equal frequencies. This problem tests our understanding of frequency counting and pattern matching. So, if the input is like s = "abbc", then the output will be True as we can delete one 'b' to get string "abc" where frequency of each character is 1. Approach To solve this, we will follow these steps ? Count frequency of all characters in the string Check if frequencies are already equal (removing any character would work) Try removing ...
Read More