Check If Large Number is Divisible by 17 in Python

Arnab Chakraborty
Updated on 30-Dec-2020 13:01:12

700 Views

Suppose, we are given a number and we have to check whether the number is divisible by 17.So, if the input is like 99943, then the output will be Divisible.We will solve this problem using the repeated subtraction method, where we extract the last digit of the number and subtract it 5 times from the number until we get a two-digit number that is divisible by 17.To solve this, we will follow these steps −while number is divisible by 100, dolast_digit := number mod 10number := floor value of (number divided by 10)number := number - last_digit * 5return true ... Read More

Check If Integer Can Be Expressed as Sum of Two Semi-Primes in Python

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

731 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 Encoding for Unique Binary String in Python

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

158 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 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

314 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 All 1s in a Binary String Are Equidistant 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

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