Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 294 of 377

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 489 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 sorting, they will be −data = {0, 14, 23, 501, 145, 129}Here we will create our own comparison logic to sort them. That comparison logic will be used in the sort function in C++ STL.Algorithmcompare(num1, num2): Begin    if sum of digits of num1 < sum of digits of num2, ...

Read More

Check if a number is Full Prime in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 408 Views

Here we will see, how to check, whether a number is full prime or not. A number is said to be a full prime, if it is prime, and all of its digits are also prime. Suppose a number is 37, this is full prime. But 97 is not full prime as 9 is not a prime number.One efficient approach is that; first we have to check whether any digit is present that is not prime. Digits must be in 0 to 9. In that range 2, 3, 5 and 7 are prime, others are not prime. If all are ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 447 Views

Here we will see how to check a number is divisible by 13 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 13, if the number satisfies the following situations −A number is divisible by 13 if and only if we get the alternating sum i.e. alternatively adding and subtracting of blocks of three numbers from right to left is divisible by 13. For example, 2911285 is divisible by 13 because the alternating sum of blocks of size 3 is 2 – 911 + 285 = ...

Read More

Tetranacci Numbers in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 267 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 - 1) + T(n - 2) + T(n - 3) + T(n - 4)The first few numbers to start, are {0, 1, 1, 2}Algorithmtetranacci(n): Begin    first := 0, second := 1, third := 1, fourth := 2    print first, second, third, fourth    for i in range n – ...

Read More

Check if a linked list is Circular Linked List in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Here we will see, hoe to check a linked list is circular linked list or not. To check whether the linked list is circular or not, we will store the header node into some other variable, then traverse the list, if we get null at the next part of any node, then that is not circular, otherwise we will check the next node is same as the stored node or not, if so then that is circular.Example#include using namespace std; class Node{    public:    int data;    Node *next; }; Node* getNode(int data){    Node *newNode = new ...

Read More

Tribonacci Word in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 269 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 one will be 1213 + 12 + 1 = 1213121Algorithmtribonacci_word(n): Begin    first := 1, second := 12, third := 1213    print first, second, third    for i in range 3 to n, do       temp := third       third := third + second + ...

Read More

Check if a number is Bleak in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 457 Views

Here we will see whether a number is Bleak or not. A number is said to be bleak if it cannot be represented as sum of a positive number x and set bit count in x. So x + set_bit_count(x) is not equal to n , for any non-negative number x.The concept is very simple, if the set bit count + the number is not same as the number, then that is Bleak, otherwise it is not.Example#include using namespace std; int set_bit_count(int x) {    unsigned int bit_count = 0;    while (x != 0) {       ...

Read More

Check if a number is divisible by all prime divisors of another number in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 570 Views

Suppose there are two numbers. We have to check whether a number is divisible by all of the prime factors or the second number or not. Suppose a number is 120. The prime factors are {2, 3, 5}, another number is 75, here the prime factors are {3, 5}. As 120 is divisible by 3 and 5 also, then the decision is yes.If one number is 1, then it has no prime divisors, so answer is True. Otherwise we have to find the GCD of these two numbers. If GCD is 1, then they are co-prime. So answer is false. ...

Read More

Check if a pair with given product exists in a Matrix in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 181 Views

We have one matrix of order N x M. And a product K. The task is to check whether a pair with the given product is present in the matrix or not.Suppose a matrix is like below −12345678910111213141516Now if the K is 42, then there is a pair like (6, 7)To solve this problem, we will use hashing. We will create hash table by taking all elements of the matrix. We will start traversing the matrix, while traversing, check whether the current element of the matrix is divisible by the given product, and when the product K is divided by ...

Read More

Minimum Initial Energy Required To Cross Street in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 507 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. We have to find the initial energy level to cross the street, such that energy level never becomes 0 or less than 0.Suppose we have an array A = {4, -6, 2, 3}. Let the initial energy is 0. So after reaching at first check point, the energy is 4. ...

Read More
Showing 2931–2940 of 3,768 articles
« Prev 1 292 293 294 295 296 377 Next »
Advertisements