Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 87 of 377

Program to find how long it will take to reach messages in a network in Python

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

In network communication, messages propagate through nodes with varying transmission times. This problem finds the minimum time needed for a message starting at node 0 to reach all nodes in an undirected network graph. Given n nodes labeled 0 to n, and edges in the form (a, b, t) where t is the transmission time between nodes a and b, we need to find how long it takes for every node to receive the message. Problem Analysis If the input is n = 3 and edges = [[0, 1, 3], [1, 2, 4], [2, 3, 2]], the ...

Read More

Program to find number of steps required to change one word to another in Python

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

Suppose we have a list of words called dictionary and we have another two strings start and end. We want to reach from start to end by changing one character at a time and each resulting word should also be in the dictionary. Words are case-sensitive. So we have to find the minimum number of steps it would take to reach at the end. If it is not possible then return -1. So, if the input is like dictionary = ["may", "ray", "rat"] start = "rat" end = "may", then the output will be 3, as we can select ...

Read More

Program to check whether odd length cycle is in a graph or not in Python

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

In graph theory, an odd-length cycle is a cycle that contains an odd number of vertices. To detect such cycles in an undirected graph, we can use Depth-First Search (DFS) with path tracking to identify back edges that form odd cycles. Problem Understanding Given an undirected graph represented as an adjacency list, we need to determine if there exists any cycle with an odd number of vertices. For example, cycles like [1, 3, 4] (length 3) or [0, 1, 3, 4, 2] (length 5) are odd-length cycles. 0 ...

Read More

Program to get indices of a list after deleting elements in ascending order in Python

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

Suppose we have a list of distinct values and we want to remove each number in non-decreasing order. We have to find the indices of numbers in order of their deletion. So, if the input is like nums = [4, 6, 2, 5, 3, 1], then the output will be [5, 2, 3, 0, 1, 0]. We delete 1 (at index 5), so array becomes [4, 6, 2, 5, 3], then remove 2 (at index 2), array becomes [4, 6, 5, 3], then remove 3 (at index 3) to get [4, 6, 5], then remove 4 (at index 0) ...

Read More

Program to check number of requests that will be processed with given conditions in python

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

When building web applications, we often need to implement rate limiting to prevent abuse. This problem demonstrates how to process requests with both per-user and global rate limits within a 60-second sliding window. We have a list of requests where each contains [uid, time_sec] representing a user ID and timestamp. We need to enforce two constraints: u (maximum requests per user in 60 seconds) and g (maximum global requests in 60 seconds). Requests at the same timestamp are processed by lowest user ID first. Example Given requests = [[0, 1], [1, 2], [1, 3]], u = 1, ...

Read More

Program to check some elements in matrix forms a cycle or not in python

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

A matrix cycle exists when we can start from a cell, move through adjacent cells with the same value, and return to the starting position without revisiting the previous cell. This problem uses depth-first search (DFS) to detect such cycles. Problem Understanding Given a 2D matrix, we need to check if we can form a cycle by moving through adjacent cells (up, down, left, right) that have the same value. The key constraint is that we cannot revisit the cell we just came from. For example, consider this matrix ? 2 2 2 1 ...

Read More

Program to count how many ways we can cut the matrix into k pieces in python

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

Suppose we have a binary matrix and a value k. We want to split the matrix into k pieces such that each piece contains at least one 1. The cutting rules are: Select a direction: vertical or horizontal Select an index in the matrix to cut into two sections If we cut vertically, we can no longer cut the left part but can only continue cutting the right part If we cut horizontally, we can no longer cut the top part and can only continue cutting the bottom part We need to find the number of ...

Read More

Program to find maximum possible population of all the cities in python

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

Consider a country represented as a tree with N nodes and N-1 edges. Each node represents a town, and each edge represents a bidirectional road. We need to upgrade some towns into cities following these constraints: no two cities should be adjacent, and every town must be adjacent to at least one city. Our goal is to find the maximum possible population of all upgraded cities. Problem Understanding Given source and dest arrays representing road connections, and a population array for each town, we need to select nodes (upgrade to cities) such that ? No two ...

Read More

Program to count subsets that sum up to k in python

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

Suppose we have a list of numbers called nums and another value k, we have to find the number of subsets in the list that sum up to k. If the answer is very large then mod this with 10^9 + 7. So, if the input is like nums = [2, 3, 4, 5, 7] k = 7, then the output will be 3, as we can choose the subsets [2, 5], [3, 4] and [7]. Algorithm To solve this, we will follow these steps − dp := a list of ...

Read More

Program to check given point in inside or boundary of given polygon or not in python

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

Suppose we have a list of cartesian points [(x1, y1), (x2, y2), ..., (xn, yn)] representing a polygon, and also have two values x and y. We need to check whether point (x, y) lies inside this polygon or on the boundary. So, if the input is like points = [(0, 0), (1, 3), (4, 4), (6, 2), (4, 0)] and pt = (3, 1): ...

Read More
Showing 861–870 of 3,768 articles
« Prev 1 85 86 87 88 89 377 Next »
Advertisements