Suppose we have a number n. We have to check whether n is dihedral prime or not. A number is said to be dihedral prime when that number is itself prime and also shown same number or any other prime number using 7-segment display regardless the orientation of the display (normal or up-side down).So, if the input is like n = 1181, then the output will be Truesecond one is up-side down format of the first one and both are prime.To solve this, we will follow these steps −Define a function up_side_down() . This will take ntemp := n, total ... Read More
Suppose we have a number n and another value k. We have to check whether the kth bit in n is set (1) or not. The value of k is considered from right hand side.So, if the input is like n = 23, k = 3, then the output will be True as binary form of 23 is 10111 so the third last bit is 1 (set).To solve this, we will follow these steps −temp := n after shifting bits (k - 1) times to the rightif temp AND 1 is 1, thenreturn Truereturn FalseLet us see the following implementation ... Read More
Suppose we have two arrays nums1 and nums2 and another value k. We have to check whether both arrays can be made equal by modifying any one element from the nums1 in the following way (only once): We can add any value from the range [-k, k] to any element of nums1.So, if the input is like nums1 = [5, 7, 11] nums2 = [5, 5, 11] k = 8, then the output will be True as we can add -2 (in range [-8, 8]) with nums1[1] to make it 5 then it will be same as nums2.To solve this, ... Read More
Suppose we have three numbers and we have to check whether they are adjacent primes are not. The adjacent primes are prime numbers where no other prime is present between them.So, if the input is like nums = [5, 7, 11], then the output will be True.To solve this, we will follow these steps −if any one of these three numbers is not prime themreturn Falseif next prime of x is not same as y, thenreturn Falseif next prime of y is not same as z, thenreturn Falsereturn TrueLet us see the following implementation to get better understanding −Example CodeLive ... Read More
Suppose we have two strings s and t and r, we have to check whether r = s | t or r = t + s where | denotes concatenation.So, if the input is like s = "world" t = "hello" r = "helloworld", then the output will be True as "helloworld" (r) = "hello" (t) | "world" (s).To solve this, we will follow these steps −if size of r is not same as the sum of the lengths of s and t, thenreturn Falseif r starts with s, thenif r ends with t, thenreturn Trueif r starts with t, ... Read More
Suppose we have a floating point number; we have to check whether the number is odd or even. In general, for integer it is easy by dividing the last digit by 2. But for floating point number it is not straight forward like that. We cannot divide last digit by 2 to check if it is odd or even.So, if the input is like n = 200.290, then the output will be Odd though the last digit is divisible by 2.To solve this, we will follow these steps −s := convert number as stringflag := Falsefor i in range size ... Read More
Suppose we have a list of degrees of some vertices. We have to check whether it is forming graph or tree.So, if the input is like deg = [2,2,3,1,1,1], then the output will be TreeTo solve this, we will follow these steps −vert := number of verticesdeg_sum := sum of all degree values of all verticesif 2*(vert-1) is same as deg_sum, thenreturn 'Tree'return 'Graph'Let us see the following implementation to get better understanding −Example CodeLive Demodef solve(deg): vert = len(deg) deg_sum = sum(deg) if 2*(vert-1) == deg_sum: return 'Tree' return 'Graph' deg = [2,2,3,1,1,1] print(solve(deg))Input[2,2,3,1,1,1] OutputTree
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP