Found 33676 Articles for Programming

Check if any anagram of a string is palindrome or not in Python

Yaswanth Varma
Updated on 30-Jul-2025 18:50:48

491 Views

Check if any Anagram of a String is Palindrome An anagram is a rearrangement of the characters of a word or a phrase to generate a new word, using all the original characters exactly once. For example, thing and night are anagrams of each other. While palindrome is a word or phrase that reads the same forward and backward, like madam, racecar. In this article, we are going to check if any anagram of a string is a palindrome or not, i.e., we are not just checking whether the given string itself is a palindrome, but also whether it can ... Read More

Check if an integer can be expressed as a sum of two semi-primes in Python

Arnab Chakraborty
Updated on 30-Dec-2020 12:52:09

732 Views

Suppose we have a number n, we have to check whether n can be expressed as a sum of two semi-primes or not.As we know the semi-prime is a number if it can be expressed as product of two primes number. First few semi-prime numbers are (1 - 100 range): 4, 6, 9, 10, 14, 15, 21, 22, 25, 26, 33, 34, 35, 38, 39, 46, 49, 51, 55, 57, 58, 62, 65, 69, 74, 77, 82, 85, 86, 87, 91, 93, 94, 95.So, if the input is like n = 108, then the output will be True as this ... Read More

Check if an encoding represents a unique binary string in Python

Arnab Chakraborty
Updated on 30-Dec-2020 12:50:11

160 Views

Suppose we have an array called nums represents an encoding of a binary string of size k, we have to check whether given encoding uniquely finds a binary string or not. Here the encoding has counts of contiguous 1s which are separated by single 0s.So, if the input is like nums = [4, 2, 3] k = 11, then the output will be True as there is a binary string like 11110110111 of k = 11.To solve this, we will follow these steps −total := sum of all elements in numstotal := total + size of nums - 1return true ... Read More

Check if an array represents Inorder of Binary Search tree or not in Python

Yaswanth Varma
Updated on 30-Jul-2025 18:44:15

581 Views

The Binary Search Tree (BST) is a widely used data structure that maintains the elements in a sorted hierarchical order. Each node in the BST follows the specific property: The values in the left subtree are always less than the values of the current node. The values in the right subtree are always greater than the node. In this article, we are going to learn about checking if an array represents the inorder of a BST or not in Python. Checking for inorder of the BST Inorder traversal is the ... Read More

Check if an array of 1s and 2s can be divided into 2 parts with equal sum in Python

Arnab Chakraborty
Updated on 30-Dec-2020 12:46:58

179 Views

Suppose we have an array nums which only stores 1 and 2 in it. We have to check whether the array can be divided into two different parts such that sum of elements in each part is same.So, if the input is like nums = [1, 1, 2, 2, 2], then the output will be True as we can divide this array like [1, 1, 2] and [2, 2] the sum of each part is 4.To solve this, we will follow these steps −total := 0, one_count := 0total := sum of all elements of numsone_count := count of 1s ... Read More

Check if an array is stack sortable in C++

Arnab Chakraborty
Updated on 30-Dec-2020 12:45:27

315 Views

Suppose we have an array nums of unique elements from 1 through n. We have to check whether it is stack-sortable or not. An array is stack sortable when it can be stored in some other array using a temporary stack.To solve this, we can use any of these operations on the array −Delete the starting element of array and push that item into the stack.Delete the top element of the stack and insert it to the end of second array.Now if all the element of the given array is transferred to the second array by these operations so the ... Read More

Check if an array contains all elements of a given range in Python

Arnab Chakraborty
Updated on 30-Dec-2020 12:41:31

2K+ Views

Suppose we have an array called nums. We also have two numbers x and y defining a range [x, y]. We have to check whether the array contains all elements in the given range or not.So, if the input is like nums = [5, 8, 9, 6, 3, 2, 4] x = 2 y = 6, then the output will be true as there are all elements [2, 3, 4, 5, 6].To solve this, we will follow these steps −temp_range := y - xfor i in range 0 to size of nums, doif |nums[i]| >= x and |nums[i]| 0, ... Read More

Check if an array can be divided into pairs whose sum is divisible by k in Python

Yaswanth Varma
Updated on 30-Jul-2025 18:29:49

253 Views

Check if Array Can Be Divided into Pairs with Sum Divisible by K In this article, we are given an array of integers and a number k. The task is to determine whether it is possible to divide the entire array into pairs such that the sum of every pair is divisible by k. For example, if the given array of integers is [2, 4, 1, 3], and a value k = 5. The task is to form pairs (two elements at a time) from the array such that when you add each pair, the result is divisible by ... Read More

Check if all the 1s in a binary string are equidistant or not in Python

Arnab Chakraborty
Updated on 30-Dec-2020 12:36:14

171 Views

Suppose we have a binary string str, we have to check whether all of the 1s in the string are equidistant or not. In other words, the distance between every two 1s is same. And the string contains at least two 1s.So, if the input is like s = "100001000010000", then the output will be True as the 1s are at distance 4 from each other.To solve this, we will follow these steps −index := a new listfor i in range 0 to size of s, doif s[i] is same as 1, theninsert i at the end of indext := ... Read More

Check if all sub-numbers have distinct Digit product in Python

Arnab Chakraborty
Updated on 30-Dec-2020 12:34:56

246 Views

Suppose we have a number n, we have to check whether all sub-numbers of this number have unique digit product or not. As we know, n digit number has n*(n+1)/2 sub-numbers. For example, the sub-numbers of 135 are 1, 3, 5, 13, 35, 135. And the digit product of a number is product of its digits.So, if the input is like n = 235, then the output will be True as sub numbers are [2, 3, 5, 23, 35, 235], digit products are [2, 3, 5, 6, 15, 30]To solve this, we will follow these steps −Define a function dig_prod() ... Read More

Advertisements