Arnab Chakraborty has Published 4282 Articles

Check if a binary string has two consecutive occurrences of one everywhere in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 14:03:49

244 Views

Here we will see another interesting problem. We have to write a code that accepts a string, which has following criteria.Every group of consecutive 1s, must be of length 2every group of consecutive 1s must appear after 1 or more 0sSuppose there is a string like 0110, this is valid ... Read More

Check if a binary string has a 0 between 1s or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 13:56:06

206 Views

Here we will see one interesting problem. We have to check whether a string has 0 in between a 1s or not. If not, then the string is valid, otherwise invalid.Suppose there are three strings −100011110100000111110001111101111From these three strings, only B is valid, because there is no 0 inside the ... Read More

Check for Integer Overflow in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 13:50:57

400 Views

The only safe way is to check for overflow before it occurs. There are some hacky ways of checking for integer overflow though. So if you're aiming for detecting overflow in unsigned int addition, you can check if the result is actually lesser than either values added. So for example, ... Read More

Find One’s Complement of an Integer in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 13:34:21

3K+ Views

In this section, we will see how to find the 1’s complete of an integer. We can use the complement operator to do this task very fast, but it will make 32bit complemented value (4-bype integer). Here we want complement of n bit numbers.Suppose we have a number say 22. ... Read More

Find number of substrings of length k whose sum of ASCII value of characters is divisible by k in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 13:14:18

374 Views

Here we will see another problem, where one string and another integer value say k is given. We have to find the number of substrings of length k, whose sum of ASCII values of characters is divisible by k.Suppose a string is “BCGABC”. And the value of k is 3. ... Read More

Find Cube Pairs - (A n^(2/3) Solution) in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 13:09:18

148 Views

A number is given. We have to find two pairs, that can represent the number as sum of two cubes. So we have to find two pairs (a, b) and (c, d) such that the given number n can be expressed as n = a3 + b3 = c3 + ... Read More

Find any pair with given GCD and LCM in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 12:56:42

332 Views

In this section we will see how to get number of pairs using the given GCD and LCM values. Suppose the GCD and LCM values are 2 and 12. Now the possible pairs of numbers are (2, 12), (4, 6), (6, 4) and (12, 2). So our program will find ... Read More

Minimum insertions to make a Co-prime array in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 12:47:05

221 Views

In this section we will see another interesting problem. Suppose we have an array of N elements. We have to find minimum number of intersection points to make this array as co-prime array. In the co-prime array gcd of every two consecutive elements is 1. We have to print the ... Read More

Minimum Initial Energy Required To Cross Street in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 12:40:05

473 Views

Suppose we have an array where positive and negative numbers are stored. The array is representing the checkpoint from one end to another end of the streets. The positive and negative values are representing the energy at the checkpoints. The positive values can increase energy, and negative number decreases energy. ... Read More

Maximum Length Chain of Pairs in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 12:32:39

247 Views

There is a chain of pairs is given. In each pair, there are two integers and the first integer is always smaller, and second one is greater, the same rule can also be applied for the chain construction. A pair (x, y) can be added after a pair (p, q), ... Read More

Advertisements