Server Side Programming Articles

Page 966 of 2109

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 316 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 394 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 205 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 416 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 563 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

A Puzzle on C/C++ R-Value Expressions?

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

Here we will see one puzzle about R-value expressions in C. Suppose there is a program which is given below, we have to tell what will be the output and why? Syntax ~expression; // R-value: computes but doesn't store variable = ~expression; // L-value: stores the result Example 1: R-value Expression In this example, the complement operation is performed but not assigned to any variable − #include int main() { int x = 0xab; ~x; /* ...

Read More

A Pancake Sorting Problem?

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

Pancake sorting is a unique sorting algorithm that mimics the process of sorting a stack of pancakes by flipping portions of the stack. In this algorithm, we can only use one operation: rev(arr, i), which reverses elements from index 0 to index i. The goal is to sort the entire array using only this flip operation. The algorithm works similarly to selection sort − we repeatedly find the largest element and move it to its correct position at the end of the current unsorted portion. Syntax void rev(int arr[], int i); int maxIndex(int arr[], int n); ...

Read More

A nested loop puzzle?

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

In this section we will see one interesting nested loop performance puzzle. We will analyze two code segments with different loop arrangements to understand which one runs faster, assuming the compiler does not optimize the code. The Problem Both code segments execute the same total number of iterations (10 × 100 = 1000), but their performance characteristics differ due to loop overhead − Segment 1: Outer Loop with Fewer Iterations #include int main() { int count = 0; for(int i ...

Read More

A matrix probability question ?

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

This problem calculates the probability of staying within a matrix after N moves from a given position. From any cell, we can move in four directions (left, right, up, down) with equal probability (0.25 each). If we cross the matrix boundary, the probability becomes 0. Syntax double matProb(int m, int n, int x, int y, int N); int isSafe(int x, int y, int m, int n); Parameters m, n − Matrix dimensions (m rows, n columns) x, y − Starting position coordinates N − Number of moves to make Algorithm ...

Read More

Print the given pattern recursively

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 4K+ Views

In C programming, we can create various patterns using recursive functions. A recursive function is one that calls itself repeatedly until a base condition is met. Here we'll learn to print a star pattern where each row contains an increasing number of stars. Syntax void printStars(int n); void printPattern(int n); Algorithm START Step 1 → function printStars(int n) If n > 0 printStars(n-1) Print * End IF End Step 2 → function printPattern(int n) ...

Read More
Showing 9651–9660 of 21,090 articles
« Prev 1 964 965 966 967 968 2109 Next »
Advertisements