Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 45 of 377

Program to find minimum limit of balls in a bag in Python

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

Suppose we have an array nums where the ith element indicates a bag containing nums[i] number of balls. We also have another value called mx. We can perform the following operation at most mx times − Select any bag of balls and divide it into two new bags with at least one ball. Here penalty is the maximum number of balls in a bag. We have to minimize the penalty after the operations. So finally, we have to find the minimum possible penalty after performing the operations. So, if ...

Read More

Program to count number of homogenous substrings in Python

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

A homogenous substring is a substring where all characters are the same. Given a string s, we need to count the total number of homogenous substrings and return the result modulo 10^9+7. Understanding the Problem For the string "xyyzzzxx", the homogenous substrings are ? "x" appears 3 times (at positions 0, 6, 7) "xx" appears 1 time (positions 6-7) "y" appears 2 times (at positions 1, 2) "yy" appears 1 time (positions 1-2) "z" appears 3 times (at positions 3, 4, 5) "zz" appears 2 times (positions 3-4, 4-5) "zzz" appears 1 time (positions 3-5) ...

Read More

Program to find max value of an equation in Python

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

Suppose we have an array called points containing coordinate points on a 2D plane, sorted by x-values, where points[i] = (x_i, y_i) and x_i < x_j for all 1

Read More

Program to find maximum score from removing stones in Python

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

Suppose we have three values a, b and c representing three piles of stones. We are playing a solitaire game where each turn the player selects two different non-empty piles, takes one stone from each, and adds 1 point to their score. The game ends when there are fewer than two non-empty piles. We need to find the maximum score possible. So, if the input is like a = 4, b = 4, c = 6, then the output will be 7 because the initial state is (4, 4, 6), then we can follow these steps − ...

Read More

Program to find minimum length of string after deleting similar ends in Python

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

Suppose we have a string s with only three characters 'a', 'b', and 'c'. We can apply the following algorithm on the string any number of times to minimize its length: Select a non-empty prefix from s where all characters in the prefix are the same. Select a non-empty suffix from s where all characters in the suffix are the same. The prefix and suffix must be disjoint (non-overlapping). The characters from the prefix and suffix must be the same. Remove both the prefix and the suffix from s. Our goal is to find the minimum ...

Read More

Program to count minimum semesters to cover all different courses in Python

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

Suppose we have a number n, indicating that there are n different courses labeled from 1 to n. We also have an array called relations where relations[i] contains a pair (prevCourse_i, nextCourse_i), representing a prerequisite relationship between the course prevCourse_i and the course nextCourse_i: so course prevCourse_i has to be taken before the course nextCourse_i. The last parameter we have is k. In one semester, we can take at most k number of courses as long as we have taken all the prerequisites in the previous semester for the courses we are taking. We have to find the minimum number ...

Read More

Program to find maximum absolute sum of any subarray in Python

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

Sometimes we need to find the maximum absolute sum of any subarray within an array. This problem extends Kadane's algorithm by considering both maximum and minimum subarray sums, as the absolute value of a negative sum might be larger than the positive maximum. Problem Understanding Given an array nums, we need to find the maximum absolute sum of any contiguous subarray. The absolute sum of a subarray [nums_l, nums_l+1, ..., nums_r] is |nums_l + nums_l+1 + ... + nums_r|. For example, if nums = [2, -4, -3, 2, -6], the subarray [2, -4, -3, 2] has sum ...

Read More

Program to check whether we can eat favorite candy on our favorite day in Python

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

Suppose we have an array of positive values candiesCount where candiesCount[i] denotes the number of candies of the ith type we have. We also have another array called queries where queries[i] has three parameters [favoriteType_i, favoriteDay_i, dailyCap_i]. We have some rules: We start eating candies on day 0. We cannot eat any candy of type i unless we have eaten all candies of previous i-1 types. We must eat at least one candy per day until we have eaten all of them. Following these rules, we have ...

Read More

Program to find out the critical and pseudo-critical edges in a graph in Python

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

A Minimum Spanning Tree (MST) contains the minimum weight edges that connect all vertices in a graph. In this problem, we need to identify critical edges (edges whose removal increases MST weight) and pseudo-critical edges (edges that can appear in some MSTs but not all). Problem Understanding Given an undirected weighted graph with n vertices (0 to n-1), we need to find: Critical edges: Removing them increases the MST weight Pseudo-critical edges: Can be part of an MST but aren't required ...

Read More

Program to find Kth ancestor of a tree node in Python

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

Suppose we have a tree with n nodes that are numbered from 0 to n-1. The tree is given by a parent array, where parent[i] is the parent of node i. The root of the tree is node 0. We have to find the kth ancestor of a given node. If the ancestor is not present, then return -1. So, if the input is like ? 0 1 2 ...

Read More
Showing 441–450 of 3,768 articles
« Prev 1 43 44 45 46 47 377 Next »
Advertisements