Articles on Trending Technologies

Technical articles with clear explanations and examples

Active and Inactive cells after k Days?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 398 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 542 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 217 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 261 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 486 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 244 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

Print values of 'a' in equation (a+b) <= n and a+b is divisible by x

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 165 Views

Given an equation where we need to find values of 'a' such that a+b ≤ n and (a+b) is divisible by x. This problem involves finding all valid values of 'a' that satisfy both the sum constraint and divisibility condition. Syntax for (divisible = (b / x + 1) * x; divisible = 1) { // divisible - b gives us the value of 'a' } } Algorithm START Step 1 → Declare variables b=10, x=9, n=40 and flag=0, divisible Step ...

Read More

Print n smallest elements from given array in their original order

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 291 Views

Given an array of elements, the program must find the n smallest elements and display them in their original order of appearance in the array. Input : arr[] = {1, 2, 4, 3, 6, 7, 8}, k=3 Output : 1, 2, 3 Input k is 3 it means 3 smallest elements among the set needs to be displayed in original order like 1 than 2 and than 3 Syntax void findNSmallest(int arr[], int size, int k); Algorithm START Step 1 −> start variables as int i, max, pos, j, k=4 ...

Read More

Print n terms of Newman-Conway Sequence

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 469 Views

The Newman-Conway Sequence is a fascinating mathematical sequence that generates integers using a recursive formula. It starts with 1, 1 and each subsequent term is calculated based on previous values in the sequence. Syntax P(n) = P(P(n - 1)) + P(n - P(n - 1)) where P(1) = P(2) = 1 Algorithm The algorithm to generate n terms of Newman-Conway sequence is − START Step 1 → Input variable n (e.g. 20) Step 2 → Initialize variables as i, p[n+1], p[1]=1, p[2]=1 Step 3 → Loop For i=3 and i

Read More
Showing 1–10 of 61,284 articles
« Prev 1 2 3 4 5 6129 Next »
Advertisements