Arnab Chakraborty has Published 4293 Articles

Fleury’s Algorithm for printing Eulerian Path or Circuit in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 14:53:48

2K+ Views

Fleury’s Algorithm is used to display the Euler path or Euler circuit from a given graph. In this algorithm, starting from one edge, it tries to move other adjacent vertices by removing the previous vertices. Using this trick, the graph becomes simpler in each step to find the Euler path ... Read More

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

221 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

179 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

376 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

357 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

126 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

297 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

193 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

444 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

Advertisements