Arnab Chakraborty has Published 4282 Articles

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

934 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

401 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

181 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

245 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

213 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

237 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

493 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

312 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

Check if a number can be expressed as sum two abundant numbers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 10:07:23

186 Views

Suppose we have a number. We have to express this as sum of two Abundant number, if yes, print the numbers, otherwise print -1. A number is said to be Abundant number is sum of all proper divisor of the number, denoted by sum(n) is greater than the value of ... Read More

Advertisements