Found 26504 Articles for Server Side Programming

Check whether given circle resides in boundary maintained by two other circles in Python

Arnab Chakraborty
Updated on 16-Jan-2021 04:28:04

169 Views

Suppose we have two radius values r1 and r2 of two concentric circles. We have another input coordinate coord and a radius value r. We have to check whether the circle whose center is placed at coord and it fits inside the boundary of two given concentric circles.So, if the input is like r1 = 4 r2 = 2 coord = (3, 0) r = 1, then the output will be True.To solve this, we will follow these steps −val := square root of(x^2 + y^2)if val + r = r1 - r2, thenreturn Truereturn FalseLet us see the following ... Read More

Check if the given number K is enough to reach the end of an array in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:52:11

163 Views

Suppose we have an array nums and another value k. We have to check whether it is possible to reach the end of the array by performing these operations or not Operation: Traverse nums and, if any non-prime value is there then decrement the value of k by 1. Now if any value is prime then refill the value of k to its initial value.So, if the input is like nums = [8, 5, 6, 7, 8], k = 2, then the output will be True as nums[0] is not prime, then make k = 1, then nums[1] is prime ... Read More

Check if the given number is Ore number or not in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:50:43

346 Views

Suppose we have a number n. We have to check whether n is an ore number or not. As we know an ore number is a number whose divisors have an integer harmonic value.So, if the input is like 28, then the output will be True as there are six divisors of 28: [1, 2, 4, 7, 14, 28], soAs 3 is an integer so 28 is an ore number.To solve this, we will follow these steps −Define a function get_all_div() . This will take ndiv := a new listfor i in range 1 to integer part of (square root ... Read More

Check if the given decimal number has 0 and 1 digits only in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:48:54

560 Views

Suppose we have a number num. We have to check whether num is consists of only 0s and 1s or not.So, if the input is like num = 101101, then the output will be True.To solve this, we will follow these steps −digits_set := a new set with all elements digits of numdelete 0 from digits_setdelete 1 from digits_setif size of digits_set is same as 0, thenreturn Truereturn FalseLet us see the following implementation to get better understanding −Example CodeLive Demodef solve(num):    digits_set = set()    while num > 0:       digit = num % 10 ... Read More

Check if the given array contains all the divisors of some integer in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:47:59

109 Views

Suppose we have an array nums, we have to check whether this array is containing all of the divisors of some integer or not.So, if the input is like nums = [1, 2, 3, 4, 6, 8, 12, 24], then the output will be True as these are the divisors of 24.To solve this, we will follow these steps −maximum := maximum of numstemp := a new listfor i in range 1 to square root of maximum, doif maximum is divisible by i, theninsert i at the end of tempif quotient of (maximum / i) is not same as i, ... Read More

Check if the given array can be reduced to zeros with the given operation performed given number of times in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:42:29

139 Views

Suppose we have an array nums and a value k, we have to check whether the elements in nums can be made 0 by performing the following operation exactly k number of times or not.Operation: The smallest element from the nums will be subtracted from all of the non-zero values of nums.So, if the input is like nums [2, 2, 3, 5] k = 3, then the output will be True because at first delete 2 from array, so the array will be [0, 0, 1, 3], then remove 1 to get [0, 0, 0, 2], then again delete 2 ... Read More

Check if the frequency of any character is more than half the length of the string in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:41:42

213 Views

Suppose we have a string s with lowercase, uppercase, numeric and special characters. We have to check whether frequency of any one of character is more than the half of length of string or not.So, if the input is like s = "CC*Ca5&CC", then the output will be True as frequency of 'C' is 5 and length of string is 9. (5 > 9/2).To solve this, we will follow these steps −freq := a map containing frequencies of characters of sfor each ch in freq, doif frequency of ch > (size of s / 2), thenreturn Truereturn FalseLet us see ... Read More

Check if the frequency of all the digits in a number is same in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:40:22

2K+ Views

Suppose we have a number num we have to check whether is balanced or not. A number is balanced when frequencies of all digits are same or not.So, if the input is like num = 562256, then the output will be True as frequency of each digit is 2.To solve this, we will follow these steps −number := convert num as stringfreq := a map containing frequencies of digits of numberfreq_values := make a new set by taking all digit frequency values from numberif size of freq_values is same as 1, thenreturn Truereturn FalseLet us see the following implementation to ... Read More

Check if the first and last digit of the smallest number forms a prime in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:38:08

246 Views

Suppose we have an array called digits that contains only digits. We have to find the minimum possible number from the given digits and then check whether the numbers by taking first and last digits of the generated number are prime or not. We will print the number itself and then the prime numbers.So, if the input is like digits = [5, 2, 1, 7], then the output will be 1257 is the smallest number. The numbers by taking first and last digits are 17 and 71, both are prime.To solve this, we will follow these steps −digits_freq := a ... Read More

Check if the elements of stack are pairwise sorted in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:37:11

325 Views

Suppose we have a stack of numbers; we have to check whether values in the stack are pairwise consecutive or not. These pairs can be increasing or decreasing. If the stack has an odd number of values, the top element is left out of a pair. And we should retain the original stack content after checking. To solve this problem, we can use three operations on stack called push, pop and check whether stack is empty or not.So, if the input is like stk = [5, 6, -4, -5, 12, 11, 6, 7, 22], then the output will be True as ... Read More

Advertisements