Found 26504 Articles for Server Side Programming

Check if an encoding represents a unique binary string in Python

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

162 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

583 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

180 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

317 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

257 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

172 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

249 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

Check if all people can vote on two machines in Python

Arnab Chakraborty
Updated on 30-Dec-2020 12:33:20

136 Views

Suppose we have a number n denotes n people and there are two identical voting machines. We also have an array called time of size n such that time[i] represents total time spent by i-th person to vote on any machine. At one time instant, only one person can be there on each of the two machines. We also have another value x, representing the maximum allowable time for which machines are operational, we have to check whether all persons can place their vote or not.So, if the input is like n = 3, x = 7, time = [3, ... Read More

Delete alternate nodes of a Linked List in C++

Hafeezul Kareem
Updated on 30-Dec-2020 07:01:21

1K+ Views

In this tutorial, we are going to learn how to delete all prime nodes from a singly linked list.Let's see the steps to solve the problem.Write struct with data and next pointer.Write a function to insert the node into the singly linked list.Initialize the singly linked list with dummy data.Iterate over the singly linked list.Delete alternate node by maintaining the previous node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move the head to next node.If the node is middle node, then link the next node to ... Read More

Advertisements