Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 181 of 377

An efficient way to check whether n-th Fibonacci number is multiple of 10?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 319 Views

Here we will see one efficient way to check whether the nth Fibonacci term is multiple of 10 or not. Suppose the Fibonacci terms are {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987}. So here 15th (counting from 0) Fibonacci term is divisible by 10. One easiest method is generating Fibonacci numbers up to given term, and check whether it is divisible by 10 or not. But this solution is not good, because it will not work for larger terms due to overflow and time complexity issues. Approach ...

Read More

Amazing stuff with system() in C / C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 933 Views

The system() function in C allows you to execute operating system commands directly from your C program. This function is available on Windows, Linux, and macOS, making it a powerful tool for interacting with the system shell and running command-line programs. Syntax #include int system(const char *command); Note: The examples below use system-specific commands that cannot be executed in an online compiler. They are provided for educational purposes to demonstrate system() function usage. Example 1: Getting Network Configuration This example shows how to retrieve IP configuration details on a Windows ...

Read More

All possible strings of any length that can be formed from a given string?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 853 Views

In this section we will see how to generate all possible strings of any length from a given string. This approach takes each combination of characters to make strings and then generates all permutations of each combination. For example, if the string is "ABC", then it will generate − {A, B, C, AB, BA, BC, CB, CA, AC, ABC, ACB, BAC, BCA, CAB, CBA} Syntax void printAllString(char str[]); Algorithm printAllString(str) Begin n := length of the string str count is 2^n – 1 ...

Read More

All possible numbers of N digits and base B without leading zeros?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 274 Views

Here we will see one problem where we have N and base B. Our task is to count all N digit numbers of base B without any leading zeros. So if N is 2 and B is 2, there will be four numbers: 00, 01, 10, 11. Only two of them are valid for this problem − 10 and 11, as they have no leading zeros. If the base is B, then there are 0 to B − 1 different digits. So BN number of different N digit values can be generated (including leading zeros). Numbers with leading zero ...

Read More

All possible co-prime distinct element pairs within a range [L, R]?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 349 Views

Here we will see how to count the number of co-prime pairs from a given range, where each number appears in at most one pair. Before discussing the logic, let us understand what co-prime numbers are. Co-prime numbers are two numbers that have no common positive divisors other than 1. In other words, the GCD (Greatest Common Divisor) of these two numbers is 1. For example, if the lower and upper limits are 1 and 6, then there are three possible pairs: (1, 2), (3, 4), and (5, 6). Each of these pairs consists of consecutive numbers, which ...

Read More

All possible binary numbers of length n with equal sum in both halves?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 310 Views

In this problem, we generate all possible binary numbers of length n where the sum of digits in the left half equals the sum of digits in the right half. For example, in the 6-bit number "100001", the left half "100" has sum 1 and the right half "001" also has sum 1, making them equal. Syntax void genAllBinEqualSumHalf(int n, char left[], char right[], int diff); Algorithm The algorithm uses recursion with backtracking − Base Case 1: When n = 0, if difference is 0, print the concatenated result Base Case 2: ...

Read More

All palindrome numbers in a list?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 391 Views

Here we will see one simple problem. We have to find all numbers that are palindrome in nature in a given list. The approach is simple, take each number from list and check it is palindrome or not, and print the number. Syntax bool isPalindrome(int n); void getAllPalindrome(int arr[], int n); Algorithm getAllPalindrome(arr, n) Begin for each element e in arr, do if e is palindrome, then print e ...

Read More

Add elements of given arrays with given constraints?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 197 Views

Here we will see a problem where we add two array elements and store them into another array following specific constraints. These constraints are − Addition should be started from 0th index of both arrays Split the sum if it is more than a single-digit number, and place each digit to the corresponding locations Remaining digits of the larger input array will be stored in the output array Syntax void addArrayConstraints(int arr1[], int arr2[], int m, int n); void splitDigit(int num, int* out, int* size); Algorithm addArrayConstraints(arr1, arr2) Begin ...

Read More

Active and Inactive cells after k Days?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 412 Views

Here we will see one interesting problem. Suppose one binary array is given of size n. Here n > 3. A true value or 1 value indicates that the active state, and 0 or false indicates inactive. Another number k is also given. We have to find active or inactive cells after k days. After every day state of ith cell will be active if the left and right cells are not same, if they are same, then it will be inactive. The left most and right most cell has no cell before and after it. So left most and ...

Read More

Rat in a Maze with multiple steps or jump allowed?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 557 Views

The rat in a maze problem is a classic backtracking algorithm. In this variation, the rat can jump multiple steps instead of moving one cell at a time. The rat starts at the top-left corner M[0, 0] and must reach the bottom-right corner M[N-1, N-1]. Each cell contains a number indicating the maximum jump distance allowed from that position. Syntax bool ratMazeSolve(int maze[N][N], int x, int y, int sol[N][N]); Rules The rat can move either towards the right or towards the down. Maze with 0 in cell indicates that the cell is blocked. ...

Read More
Showing 1801–1810 of 3,768 articles
« Prev 1 179 180 181 182 183 377 Next »
Advertisements