Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 11 of 81

Print the alternate nodes of linked list (Iterative Method) in C language

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

In this problem, we need to print alternate nodes from a linked list, which means printing every other node starting from the first node. The iterative method uses loops to traverse the linked list and prints nodes at even positions (0th, 2nd, 4th, etc.). For example, if the list contains nodes 29, 34, 43, 56, and 88, the output will be alternate nodes: 29, 43, and 88. 29 34 43 ...

Read More

Print numbers in matrix diagonal pattern in C Program.

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

In C programming, we can create a matrix pattern where numbers are filled in diagonal order. This pattern fills elements starting from the top-left corner, moving diagonally down and to the right. .cell { fill: #f0f0f0; stroke: #333; stroke-width: 1; } .text { font-family: Arial; font-size: 14px; text-anchor: middle; dominant-baseline: middle; } .arrow { stroke: #007acc; stroke-width: 2; fill: none; marker-end: url(#arrowhead); } .diagonal { stroke: ...

Read More

Print middle level of perfect binary tree without finding height in C language

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

In C, printing the middle level of a perfect binary tree without calculating its height is achieved using a two-pointer technique. This approach uses two traversal pointers moving at different speeds to identify when we reach the middle level. A perfect binary tree is one where all interior nodes have exactly two children and all leaf nodes are at the same level. 12 21 32 41 ...

Read More

Print pair with maximum AND value in an array in C Program.

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

In this problem, we are given an array of n positive integers and need to find a pair with the maximum AND value. The bitwise AND operation combines bits where both operands have 1 in the same position. Syntax int maxAND(int arr[], int n); int checkBit(int pattern, int arr[], int n); Algorithm Approach The algorithm works by building the maximum AND value bit by bit from the most significant bit (MSB) to the least significant bit (LSB). For each bit position, it checks if at least two numbers in the array have that bit ...

Read More

Print Leaf Nodes at a given Level in C language

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

In C programming, printing leaf nodes at a given level in a binary tree involves traversing the tree to a specific level and identifying nodes that have no children. A leaf node is a node whose both left and right pointers are NULL. Syntax void printLeafNodes(struct node* root, int level); Algorithm The approach uses recursive traversal − Base case: If root is NULL, return Target level: If level == 1, check if current node is a leaf Recursive case: If level > 1, recursively call for left and right subtrees with level-1 ...

Read More

Print the longest prefix of the given string which is also the suffix of the same string in C Program.

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

Given a string, we need to find the length of the longest prefix which is also a suffix of the same string. For example, in the string "abcab", "ab" is both a prefix and suffix with length 2. Syntax int longest_prefix_suffix(char str[], int n); Algorithm The approach uses the KMP (Knuth-Morris-Pratt) failure function concept − Start comparing from the middle of the string to avoid overlap Use two pointers: one for prefix (length) and one for suffix (i) When characters match, increment both pointers When they don't match, reset according to the ...

Read More

Print modified array after multiple array range increment operations in C Program.

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

Given an array arr[m] with m number of integers and n, which is the value to be added in an array and r queries are given with some start and end. For each query we have to add value n from the start till the end of the limit in an array. Syntax struct range { int start, end; }; void add_tomatrix(int arr[], struct range r[], int n, int size, int m); Example Input and Output Input: arr[] = {1, 2, 3, 4, 5} query[] = { { 0, ...

Read More

Print lower triangular matrix pattern from given array in C Program.

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

Given a matrix of n x n, the task is to print that matrix in lower triangular pattern. A lower triangular matrix is a matrix which has elements below the principal diagonal including the principal diagonal elements, with all other elements set as zero. Let's understand this with help of a diagram − Original Matrix 1 2 ...

Read More

Print the arranged positions of characters to make palindrome in C Program.

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

You are provided with a string str with some length n. Print the position of every element of the string so it can form a palindrome, else print a message "No palindrome" on screen. What is palindrome? Palindrome is a word, sequence of characters which reads same from the reverse or backward as from the forward manner, like MADAM, racecar. To find a sequence or a word is palindrome we generally store the reverse of a word in a separate string and compare both if they are same then the given word or sequence is palindrome. But ...

Read More

Print steps to make a number in form of 2^X – 1 in C Program.

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

Given a number n, we have to print the steps to make the number in the form of 2^X-1 by using XOR operation and increment operations. At odd steps, XOR the number with any 2^M-1, where M is the position of the leftmost unset bit. At even steps, increment the number by 1. Keep performing these steps until n becomes 2^X-1 (a number with all bits set), and print all the steps. Syntax int find_leftmost_unsetbit(int n); void perform_steps(int n); Algorithm The algorithm works by finding the leftmost unset bit and ...

Read More
Showing 101–110 of 809 articles
« Prev 1 9 10 11 12 13 81 Next »
Advertisements