Arnab Chakraborty has Published 4293 Articles

Check if a number is power of 8 or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 22-Oct-2019 06:32:41

503 Views

In this section, we will see, if a number is the power of 8 or not using some easier method. If a number like 4096 is there, then the program will return true, as this is the power of 8.The trick is simple. we will calculate log8(num). If this is ... Read More

Check if a number is positive, negative or zero using bit operators in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 22-Oct-2019 06:28:58

2K+ Views

Here we will check whether a number is positive, or negative or zero using bit operators. If we perform shifting like n >> 31, then it will convert every negative number to -1, every other number to 0. If we perform –n >> 31, then for positive number it will ... Read More

Check if a number is perfect square without finding square root in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 22-Oct-2019 06:24:50

1K+ Views

Suppose a number is given, we have to check whether the number is a perfect square or not. We will not use the square root operation to check it. Suppose a number 1024 is there, this is a perfect square, but 1000 is not a perfect square. The logic is ... Read More

Check if a number is multiple of 5 without using / and % operators in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 22-Oct-2019 06:13:52

728 Views

Here we will see how to check a number is divisible by 5 or not. One simple approach is that if the number mod 5 = 0, then, the number is divisible by 5. But here we will not use / or % operator. To check whether a number is ... Read More

Check if a number is jumbled or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 22-Oct-2019 06:12:01

493 Views

Here we will see one interesting problem to check whether a number is jumbled or not. A number is said to be jumbled if, for every digit, it's neighbor digit differs by max 1. For example, a number 1223 is jumbled, but 1256 is not jumbled.To solve this problem, we ... Read More

Check if a number is in given base or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 22-Oct-2019 06:06:27

252 Views

Suppose, we have a number string, we have to find that the number is of given base B or not? If the string is “101110”, b = 2, then the program will return true. If the string is “A8F”, base is 16, it will be true.The approach is very simple. ... Read More

Check given array of size n can represent BST of n levels or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:31:49

93 Views

We have an array A, we have to check whether the array can represent a BST with n levels or not. As the level is , we can construct a tree in following manner. Assume a number is k, value greater than k moves to right side, and less than ... Read More

Check given matrix is magic square or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:28:42

2K+ Views

Here we will see, if a matrix is magic square or not, a magic square is a square matrix, where the sum of each row, each column, and each diagonal are same.Suppose a matrix is like below −618753294This is a magic square, if we see, the sum of each row, ... Read More

Check for possible path in 2D matrix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:25:13

620 Views

Consider we have a 2D array. We have to find if we can get a path from topleft corner to bottom-right corner. The matrix is filled with 0s and 1s. 0 indicates open area, 1 indicates blockage. Note that the top-left corner will always be 1.Suppose a matrix is like ... Read More

Check for Palindrome after every character replacement Query in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:21:21

199 Views

Consider we have a string and some queries in set Q. Each query contains a pair of integers i and j. and another character c. We have to replace characters at index i and j with the new character c. And tell if the string is palindrome or not. Suppose ... Read More

Advertisements