Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 107 of 377

Program to reverse the directed graph in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

A directed graph reversal means changing the direction of all edges − if an edge goes from node u to v, it becomes an edge from v to u. Given an adjacency list representation, we need to create the reverse graph where all edge directions are flipped. Problem Understanding Consider a directed graph with nodes numbered from 0 to n-1. If the original graph has an edge from node i to node j, the reversed graph will have an edge from node j to node i. Original Graph ...

Read More

Program to reverse a linked list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 599 Views

A linked list is a linear data structure where elements are stored in nodes, and each node contains data and a pointer to the next node. Reversing a linked list means changing the direction of pointers so that the last node becomes the first node. For example, if we have a linked list: 2 → 4 → 6 → 8, the reversed list will be: 8 → 6 → 4 → 2. Approach We can reverse a linked list using a recursive approach with these steps − Define a recursive function ...

Read More

Program to remove duplicate entries in a linked list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 276 Views

Suppose we have a linked list of numbers, we have to remove those numbers which appear multiple times in the linked list (hold only one occurrence in the output), we also have to maintain the order of the appearance in the original linked list. So, if the input is like [2 −> 4 −> 6 −> 1 −> 4 −> 6 −> 9], then the output will be [2 −> 4 −> 6 −> 1 −> 9]. Algorithm To solve this, we will follow these steps − if node is not null, then l ...

Read More

Program to update elements in a given range in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 395 Views

Suppose we have a list of numbers called nums and a list of operations. Each operation has three fields [L, R, X], which indicates that we should increment by X all the elements from indices L to R (inclusive). We have to apply all operations and return the final list. So, if the input is like nums = [8, 4, 2, -9, 4] and operations = [[0, 0, 3], [1, 3, 2], [2, 3, 5]], then the output will be [11, 6, 9, -2, 4]. Step-by-Step Process Let's trace through the operations with the initial list [8, ...

Read More

Program to find how many total amount of rain we can catch in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 191 Views

The rainwater trapping problem involves calculating how much water can be trapped between elevation bars after it rains. Given an array representing bar heights, we need to find the total trapped water volume. ...

Read More

Program to count number of ways we can distribute coins to workers in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 400 Views

Suppose we have two lists of positive numbers called coins and salaries. Here coins[i] indicates the value for coin i and salaries[j] indicates the least amount of salary required to pay for worker j. We have one coin per type and must give each worker exactly one coin. We need to compute the number of ways to distribute coins to workers such that each worker receives a coin with value greater than or equal to their required salary. Two ways are different if some worker receives one type of coin in one way but a different type of coin ...

Read More

Program to count how many ways we can divide the tree into two trees in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 252 Views

Suppose we have a binary tree containing values 0, 1 and 2. The root has at least one 0 node and one 1 node. We need to find how many ways we can delete one edge such that the resulting two trees don't both contain 0 and 1 nodes. In other words, after deleting an edge, each resulting subtree should contain either only 0s and 2s, or only 1s and 2s, but not both 0s and 1s together. Example Tree Structure 0 0 ...

Read More

Program to find leaf and non-leaf nodes of a binary tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

In a binary tree, a leaf node has no children, while a non-leaf node has at least one child. This program counts both types of nodes using a recursive approach that traverses the entire tree. So, if the input is like: 6 2 ...

Read More

Program to check whether inorder sequence of a tree is palindrome or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 327 Views

Suppose we have a binary tree where each node contains a digit from 0-9, we have to check whether its in-order traversal is palindrome or not. So, if the input is like 6 2 6 10 2 then the output will be True, ...

Read More

Program to count maximum number of distinct pairs whose differences are larger than target in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 373 Views

Suppose we have a list of numbers called nums and another value target. We have to find the maximum number of pairs where for each pair i < j, i and j are not in any other pair, and |nums[i] - nums[j]| >= target. So, if the input is like nums = [2, 4, 6, 10, 11], target = 5, then the output will be 2, as we can get pairs: (2, 10) and (4, 11). Algorithm To solve this problem, we will follow these steps ? Sort the array to enable efficient pairing Use ...

Read More
Showing 1061–1070 of 3,768 articles
« Prev 1 105 106 107 108 109 377 Next »
Advertisements