Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 84 of 377

Program to Find Out the Edges that Disconnect the Graph in Python

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

An edge in a graph is called a bridge (or cut-edge) if removing it increases the number of connected components. In other words, removing a bridge edge disconnects the graph. We can find bridge edges using Tarjan's algorithm with depth-first search. Algorithm Overview The algorithm uses DFS to assign discovery times to each node and tracks the lowest discovery time reachable from each subtree. An edge is a bridge if there's no back edge from the subtree that can reach an ancestor. Example Let's implement the bridge-finding algorithm ? class Solution: ...

Read More

Program to Find Out the Occurrence of a Digit from a Given Range in Python

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

When working with digit counting problems, we need to find how many times a specific digit appears in a range of numbers. This problem asks us to count occurrences of digit d in all numbers from 1 to n. For example, if n = 45 and d = 5, we need to count digit 5 in numbers: [5, 15, 25, 35, 45], giving us a total count of 5. Using Recursive Approach The recursive solution breaks down the problem by processing digits systematically ? class Solution: def solve(self, n, d): if n < 0: return 0 k = n // 10 - 1 ans = self.solve(k, d) * 10 + k + 1 if d == 0: ans -= 1 m = n // 10 * 10 while m

Read More

Program to Find Out Currency Arbitrage in Python

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

Currency arbitrage is a strategy where we exploit differences in exchange rates to make a profit. Given an N x N table of currency exchange rates, we need to check whether there's a sequence of trades that can turn some amount A of any currency into an amount greater than A of the same currency. 1 CAD 0.65 EUR 0.7865 USD 1.00672 CAD ...

Read More

Program to Connect a Forest in Python

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

Given a forest (collection of disconnected trees) represented as an adjacency list, we need to connect all trees into a single tree by adding the minimum number of edges. The goal is to minimize the diameter (longest path between any two nodes) of the resulting connected tree. 0 1 2 3 4 ...

Read More

Program to find out the efficient way to study in Python

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

Suppose we have three lists of equal length representing course assignments: deadlines, credits, and durations. For the i-th assignment, deadlines[i] shows its deadline, credits[i] shows its credit value, and durations[i] shows the days needed to complete it. We must complete one assignment before starting another, and we can finish an assignment on its due date. We start at day 0. The goal is to find the maximum credits we can earn by efficiently scheduling assignments within their deadlines. Example Problem If we have deadlines = [7, 5, 10], credits = [8, 7, 10], and durations = [5, ...

Read More

Program to find maximum value by inserting operators in between numbers in Python

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

When given a list of numbers, we need to find the maximum value possible by inserting binary operators (+, -, *) and parentheses between them. This problem uses dynamic programming to explore all possible combinations of operations. For example, with nums = [-6, -4, -10], we can create the expression ((-6) + (-4)) * -10 = (-10) * (-10) = 100. Algorithm Steps The solution uses a recursive approach with memoization: For each subarray, calculate both minimum and maximum possible values Try all possible split points and operators Combine results from left and right subarrays ...

Read More

Program to find max values of sublists of size k in Python

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

Finding maximum values in sliding windows of size k is a common problem. We'll explore three approaches: brute force, optimized tracking, and using a deque for efficient sliding window maximum. Problem Understanding Given a list nums = [12, 7, 3, 9, 10, 9] and k = 3, we need to find the maximum value in each sublist of size 3: [12, 7, 3] → max = 12 [7, 3, 9] → max = 9 [3, 9, 10] → max = 10 [9, 10, 9] → max = 10 Method 1: Brute Force Approach ...

Read More

Program to find length of longest sublist whose sum is 0 in Python

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

Suppose we have a list with only two values 1 and −1. We have to find the length of the longest sublist whose sum is 0. So, if the input is like nums = [1, 1, −1, 1, 1, −1, 1, −1, 1, −1], then the output will be 8, as the longest sublist is [−1, 1, 1, −1, 1, −1, 1, −1] whose sum is 0. Algorithm To solve this, we will follow these steps − Create an empty hash map to store cumulative sum positions ...

Read More

Program to find length of longest substring which contains k distinct characters in Python

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

Finding the length of the longest substring with at most k distinct characters is a classic sliding window problem. We use two pointers to maintain a valid window and a hash map to track character frequencies. Problem Understanding Given a string s and number k, we need to find the maximum length of any substring that contains at most k distinct characters. For example, if k = 3 and s = "kolkata", the longest substrings with at most 3 distinct characters are "kolk" and "kata", both having length 4. Algorithm Steps We use the sliding ...

Read More

Program to find length of the longest path in a DAG without repeated nodes in Python

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

Finding the longest path in a Directed Acyclic Graph (DAG) without repeated nodes is a classic dynamic programming problem. Since the graph has no cycles, we can use memoization with depth-first search to efficiently compute the longest path from any starting node. Problem Understanding Given a DAG represented as an adjacency list, we need to find the length of the longest simple path (without repeated nodes). The example graph below shows nodes 0-4 with the longest path being 0 → 1 → 3 → 4 → 2 with length 4. ...

Read More
Showing 831–840 of 3,768 articles
« Prev 1 82 83 84 85 86 377 Next »
Advertisements