Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 41 of 377

Program to find number of ways to split array into three subarrays in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 787 Views

Suppose we have an array called nums, we have to find the number of good ways to split this array. A split is considered good if the array is divided into three non-empty contiguous subarrays where sum(left) ≤ sum(middle) ≤ sum(right). Since the answer may be large, return result modulo 10^9 + 7. Problem Understanding If the input is nums = [2, 3, 3, 3, 7, 1], then the output will be 3 because there are three different ways of splitting − [2], [3], [3, 3, 7, 1] → sums: 2 ≤ 3 ≤ 11 [2], ...

Read More

Program to find out an MST using Prim's algorithm in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

A Minimum Spanning Tree (MST) is a subset of edges in a weighted graph that connects all vertices with the minimum possible total edge weight and no cycles. Prim's algorithm builds the MST by starting from a vertex and greedily adding the minimum weight edge that connects a visited vertex to an unvisited one. Original Graph ...

Read More

Program to find out the minimum moves in a snakes and ladders game in Python

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

The Snakes and Ladders game requires finding the minimum number of dice rolls to reach position 100 from position 1. In this problem, we can roll any number from 1 to 6 on the dice, and the board contains ladders (which help us climb up) and snakes (which make us slide down). We'll use a Breadth-First Search (BFS) approach to find the shortest path, as BFS guarantees finding the minimum number of moves in an unweighted graph. Problem Understanding Given the positions of ladders and snakes: Ladders: [(start, end)] where end > start (move forward) ...

Read More

Program to count good meals with exactly two items in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 334 Views

Suppose we have an array deli where deli[i] is the deliciousness of the ith food. We need to find the number of different good meals we can make from this list. A good meal contains exactly two different food items with a sum of deliciousness that is a power of two. If the answer is too large, return the result modulo 10^9 + 7. So, if the input is like deli = [1, 7, 3, 6, 5], then the output will be 3 because we can make pairs (1, 3), (1, 7) and (3, 5) whose sums are powers ...

Read More

Program to find maximum number of eaten apples in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 421 Views

Suppose we have two arrays called apples and days of same length n. There is a special kind of apple tree that grows apples every day for n consecutive days. On the ith day, it grows apples[i] number of apples that will rot after days[i] days. We can take at most one apple a day and want to find the maximum number of apples we can eat. So, if the input is like apples = [1, 2, 3, 5, 2] and days = [3, 2, 1, 4, 2], then the output will be 7 because ? On ...

Read More

Program to find Reordered Power of 2 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 209 Views

Given a positive integer N, we need to check if we can reorder its digits to form a power of 2. The reordered number must have no leading zeros. For example, if N = 812, we can rearrange it to 128, which is 2^7, so the answer is True. Algorithm To solve this problem, we will follow these steps − Start with i = 1 (which is 2^0) While i ≤ 1000000000, do the following: Convert i to string and sort its digits Convert N to string and sort its digits If both sorted ...

Read More

Program to find maximum binary string after change in python

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

Given a binary string, we can apply two types of operations any number of times to maximize its numeric value: Replace substring "00" with "10" Replace substring "10" with "01" We need to find the maximum possible binary string after applying these operations. Understanding the Problem The key insight is that we want to move as many 1s as possible to the left (higher positions) while keeping at least one 0 in the string. The operations allow us to: "00" → "10": Creates a 1 to the left of a 0 "10" ...

Read More

Program to find maximum average pass ratio in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 261 Views

Suppose we have a list of classes where classes[i] = [pass_i, total_i] represents the number of students who passed and the total number of students in the ith class respectively. We also have extra brilliant students guaranteed to pass any exam they're assigned to. We need to assign these extra students to maximize the average pass ratio across all classes. The pass ratio of a class is passed_students / total_students. The average pass ratio is the sum of all class ratios divided by the number of classes. Algorithm Approach We use a greedy approach with a max-heap ...

Read More

Program to find average waiting time in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 852 Views

Suppose we have an array customers, where customers[i] = [arrival_i, time_i]. Here arrival_i is the arrival time of the ith customer and time_i is the time needed to prepare the order. The cook processes orders sequentially and can only prepare one order at a time. We need to find the average waiting time of all customers. The waiting time for each customer is the total time from arrival until their order is completed. Problem Understanding Let's understand with an example. If the input is customers = [[7, 2], [8, 4], [10, 3], [20, 1]], then ? ...

Read More

Program to find center of star graph in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 625 Views

A star graph is an undirected graph with n nodes where one central node connects to all other n-1 nodes. In this tutorial, we'll learn how to identify the center node of a star graph represented as a list of edges. Understanding the Problem Given a star graph with n nodes labeled from 1 to n, we need to find the center node. The center node appears in every edge since it connects to all other nodes. ...

Read More
Showing 401–410 of 3,768 articles
« Prev 1 39 40 41 42 43 377 Next »
Advertisements