Arnab Chakraborty has Published 4293 Articles

Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 12:25:24

229 Views

Suppose we have a complete graph; we have to count number of Edge Disjoint Spanning trees. The Edge Disjoint Spanning trees are spanning trees, where no two trees in the set have an edge in common. Suppose the N (number of vertices) is 4, then output will be 2. The ... Read More

Sorting an array according to another array using pair in STL in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 12:20:28

898 Views

Suppose we have two different arrays. We have to sort one array based on the other array using C++ STL pair class. Consider two arrays are like A1 = [2, 1, 5, 4, 9, 3, 6, 7, 10, 8], and another array is like A2 = [A, B, C, D, ... Read More

Sort the array of strings according to alphabetical order defined by another string in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 12:18:01

368 Views

Suppose we have an array of strings, and another string is there for the reference. We have to take the reference string and using the order of the characters in the reference string we will sort the string array. Here we are considering the strings in the array, and the ... Read More

Sort elements of the array that occurs in between multiples of K in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 12:15:15

150 Views

Suppose we have an array A, and another integer K. We have to sort the elements that are in between any two multiples of K. Suppose A is like [2, 13, 3, 1, 21, 7, 8, 13, 12], and K = 2. The output will be [2, 1, 3, 7, ... Read More

Check if a number is formed by Concatenation of 1, 14 or 144 only in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 10:27:08

234 Views

Here we will see one problem, that can tell that whether a string or a number is a concatenation of 1, 14 or 144 only. Suppose a string is “111411441”, this is valid, but “144414” is not valid.The task is simple, we have to fetch a single digit, double-digit and ... Read More

Check if a number is divisible by 41 or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 10:22:18

190 Views

Here we will see one program, that can check whether a number is divisible by 41 or not. Suppose a number 104413920565933 is given. This is divisible by 41.To check the divisibility, we have to follow this rule −Extract the last digit of the number/truncated number every timesubtract 4 * ... Read More

Check if a number is divisible by 23 or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 10:19:20

216 Views

Here we will see one program, that can check whether a number is divisible by 23 or not. Suppose a number 1191216 is given. This is divisible by 23.To check the divisibility, we have to follow this rule −Extract the last digit of the number/truncated number every timeadd 7 * ... Read More

Check if a number is a Krishnamurthy Number or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 10:16:33

2K+ Views

Here we will see how to check a number is Krishnamurty number or not. A number is Krishnamurty number, if the sum of the factorial of each digit is the same as the number. For example, if a number is 145, then sum = 1! + 4! + 5! = ... Read More

Check if a number has bits in alternate pattern - Set-2 O(1) Approach in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 10:12:32

465 Views

Let us consider we have an integer n. The problem is to check, whether this integer has alternate patterns in its binary equivalent or not. The alternate pattern means 101010….The approach is like: calculate num = n XOR (n >> 1), now if all bits of num is 1, then ... Read More

Check if a number has bits in alternate pattern - Set 1 in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 10:08:52

283 Views

Let us consider we have an integer n. The problem is to check, whether this integer has alternate patterns in its binary equivalent or not. The alternate pattern means 101010….The approach is like: check each digit using binary equivalent, and if two consecutive are same, return false, otherwise true.Example#include ... Read More

Advertisements