Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1343 of 2650
623 Views
Suppose we have two numbers x and y. We have to check whether one of these two numbers is 1's complement of the other or not. We all know the 1's complement of a binary number is flipping all bits from 0 to 1 or 1 to 0.So, if the input is like x = 9, y = 6, then the output will be True as the binary representations are x = 1001 and y = 0110 which are complement of each other.To solve this, we will follow these steps −z = x XOR yreturn true when all bits in ... Read More
552 Views
Suppose we have a number which is either in octal or in decimal form. If this is in octal form check whether it is palindrome or not. If the number in decimal, then convert it to octal then check whether it is palindrome or not.So, if the input is like num = 178, then the output will be True as the number is not in octal form (8 is not valid symbol in octal but valid in decimal), then convert it to octal which is 262 and this is palindrome.To solve this, we will follow these steps −base := 8 ... Read More
1K+ Views
Suppose we have a number n, and we have another input c. We have to check whether n can be displayed using 7-segment displays or not. Now here is a constraint. We are only allowed to glow at most c number of LEDs.So, if the input is like n = 315 c = 17, then the output will be True as 315 needs 12 LEDs and we have 17.To solve this, we will follow these steps −seg := a list containing led counts for all digits : [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]s := n as ... Read More
713 Views
Suppose we have a number n. We have to check whether n is a strong prime or not. As we know a number said to be strong prime when it is a prime number that is greater than the average of nearest prime numbers.So, if the input is like num = 37, then the output will be True as nearest prime numbers are 31 and 41, the average is (31+41)/2 = 36. And 37 > 36.To solve this, we will follow these steps −if num is not prime or num is 2, thenreturn Falselast := num - 1, next := ... Read More
441 Views
Suppose we have two numbers x and n. We have to check whether x is divisible by 2^n or not without using arithmetic operators.So, if the input is like x = 32 n = 5, then the output will be True as 32 = 2^5.To solve this, we will follow these steps −if x AND (2^n - 1) is 0, thenreturn Truereturn FalseExampleLet us see the following implementation to get better understanding − Live Demodef solve (x, n): if (x & ((1
176 Views
Suppose we have a number n. We have another two numbers a and b. We have to check whether we can generate a number using a and b that divides n.So, if the input is like n = 115, a = 3, b = 2, then the output will be True as 115 is divisible by 23 which is made of 2 and 3.To solve this, we will follow these steps −Define a function util() . This will take temp, a, b, nif temp > n, thenreturn Falseif n is divisible by temp, thenreturn Truereturn true when at least one ... Read More
641 Views
Suppose we have a number n, we have to check whether n is a Factorial prime or not. As we know a number is said to be a factorial prime when it is a prime number that is one less than or one more than a factorial of any number.So, if the input is like n = 719, then the output will be True as 719 = 720 - 1 = 6! - 1To solve this, we will follow these steps −if num is not a prime, thenreturn Falsefactorial := 1, i := 1while factorial
447 Views
Suppose we have a number target. We have another two numbers A and B. We have to check whether we can get target by adding A and B as many times as we want.So, if the input is like Target = 26 A = 5 B = 7, then the output will be True as we can get 26 by adding A and B like (7 + 7 + 7 + 5).To solve this, we will follow these steps −Define a function util() . This will take x, a, b, is_ok, targetif x > target, thenreturnif is_ok[x] is True, thenreturnis_ok[x] ... Read More
195 Views
Suppose we have one binary list, where 1 denotes push operation and 0 denotes a pop operation on a stack or a queue. We have to check whether the possible set of operations are valid or not.So, if the input is like nums = [1, 0, 1, 1, 0, 1], then the output will be True as the sequence is [Push, Pop, Push, Push, Pop, Push] as we are not popping element from empty list so these operations are valid.To solve this, we will follow these steps −push_count := 0for i in range 0 to size of nums - 1, ... Read More
582 Views
Suppose we have a number n. We have to check whether the mirror image of the number is same as the given number or not when it is displayed on Seven Segment display.So, if the input is like n = 818, then the output will be True.the mirror image is same.To solve this, we will follow these steps −num_str := n as stringfor i in range 0 to size of num_str - 1, doif num_str[i] is not nay of ['0', '1', '8'] then, thenreturn Falseleft := 0right := size of num_str - 1while left < right, doif num_str[left] is not ... Read More