Arnab Chakraborty has Published 3734 Articles

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

383 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 any pair with given GCD and LCM in C++

Arnab Chakraborty

Arnab Chakraborty

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

355 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

243 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

495 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

Tribonacci Word in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 12:17:14

259 Views

The Tribonacci Word is a sequence of digits. This is similar to the Fibonacci Words. Tribonacci Word is constructed by repeated concatenation of three previous stringsT(n) = T(n - 1) + T(n - 2) + T(n - 3)The first few strings to start, are {1, 12, 1213} So the next ... Read More

Tetranacci Numbers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 12:10:21

245 Views

Here we will see how to generate the Tetranacci numbers using C++. The Tetranacci numbers are similar to the Fibonacci numbers, but here we are generating a term by adding four previous terms. Suppose we want to generate T(n), then the formula will be like below −T(n) = T(n - ... Read More

Sort the numbers according to their sum of digits in C++

Arnab Chakraborty

Arnab Chakraborty

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

470 Views

In this section we will see how to sort numbers according to their sum of digits. So if a number has lesser sum of digits, then that will be placed at first, then next number will be placed with larger sum of digits.data = {14, 129, 501, 23, 0, 145}after ... Read More

Sort an array of strings according to string lengths in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 11:51:12

1K+ Views

Here we will see how to sort a list of strings based on their lengths. So if a string has less number of characters, then that will be placed first, then other longer strings will be placed. Suppose the strings arestr_list = {“Hello”, “ABC”, “Programming”, “Length”, “Population”}after sorting, they will ... Read More

Sort an array according to the order defined by another array in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Sep-2019 11:47:56

396 Views

In this section we will see another sorting problem. Suppose we have two arrays A1 and A2. We have to sort A1 in such a way that the relative order among the elements will be same as those are in A2. If some elements are not present in A2, then ... Read More

Advertisements