Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 11 of 377

Program to find maximum profit after cutting rods and selling same length rods in Python

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

Suppose we have a list of rod lengths called rodLen. We also have two integers called profit and cost, representing profit per length and cost per cut. We can gain profit per unit length of a rod but we can only sell rods that are all of the same length. We can also cut a rod into two pieces such that their lengths are integers, but we have to pay cost amount for each cut. We can cut a rod as many times as we want. We have to find the maximum profit that we can make. So, if ...

Read More

Program to find maximum length of k ribbons of same length in Python

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

Suppose we have a list of positive numbers representing ribbon lengths and a value k. We can cut the ribbons as many times as we want, and we need to find the largest length r such that we can have k ribbons of length r. If no such solution exists, return -1. So, if the input is like ribbons = [1, 2, 5, 7, 15] and k = 5, then the output will be 5. We can cut the ribbon of size 15 into 3 pieces of length 5 each, cut the ribbon of size 7 into pieces of ...

Read More

Program to count substrings with all 1s in binary string in Python

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

Suppose we have a binary string s. We have to find the number of substrings that contain only "1"s. If the answer is too large, mod the result by 10^9+7. So, if the input is like s = "100111", then the output will be 7, because the substrings containing only "1"s are ["1", "1", "1", "1", "11", "11" and "111"]. Algorithm To solve this, we will follow these steps − Initialize a counter a to 0 for tracking consecutive 1s Initialize count to 0 for total substrings ...

Read More

Program to count number of square submatrices in given binary matrix in Python

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

A square submatrix is a subset of elements from a matrix arranged in a square pattern. In a binary matrix, we want to count square submatrices where all elements are 1. This problem uses dynamic programming to efficiently count all possible squares. Problem Understanding Given a binary matrix, we need to find the total number of square submatrices containing only 1s. For example: 0 1 1 0 1 1 This matrix has 5 square submatrices: one (2×2) square and four (1×1) squares. Algorithm Approach We use dynamic programming ...

Read More

Program to count number of intervals that is totally contained inside other intervals in Python

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

Suppose we have a list of intervals where each interval[i] has [start, end] values. We need to find the number of intervals that are completely contained inside other intervals. If an interval is contained by multiple other intervals, it should only be counted once. An interval [s0, e0] is inside another interval [s1, e1] when s1 ≤ s0 and e0 ≤ e1. So, if the input is like intervals = [[2, 6], [3, 4], [4, 7], [5, 5]], then the output will be 2, because [3, 4] is inside [2, 6] and [5, 5] is inside [4, 7]. ...

Read More

Program to find all contiguously increasing numbers in start end range in Python

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

Suppose we have two numbers start and end, we have to find a sorted list of integers such that every number e in range [start, end] both inclusive and the digits of e are contiguously increasing. An example of continuously increasing number is 5678, but 169 is not. So, if the input is like start = 10 end = 150, then the output will be [12, 23, 34, 45, 56, 67, 78, 89, 123] Algorithm To solve this, we will follow these steps − s := all 9 digits as a ...

Read More

Program to count number of ways to win at most k consecutive games in Python

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

We need to find the number of ways to play n games such that we never win more than k consecutive games. Each game can result in a win (W) or loss (L), and we must ensure no sequence of k+1 consecutive wins occurs. For example, if n = 3 and k = 2, the valid sequences are: "LLL", "WLL", "LWL", "LLW", "WWL", "LWW", "WLW" (7 ways total). Approach We'll use dynamic programming with memoization. The key insight is to track the current position in the game sequence and the number of consecutive wins so far ? ...

Read More

Program to sort all elements in a given list and merge them into a string in Python

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

Suppose we are given a list of positive integers. We have to sort the list in descending order and then join all the elements to form a string. The goal is to arrange numbers so that the resulting concatenated string represents the largest possible number. So, if the input is like input = [415, 78, 954, 123, 5], then the output will be 954785415123. Approach To solve this, we need a custom comparison function that determines which of two numbers should come first when concatenated ? Define a function cmp() that takes two parameters l ...

Read More

Program to find a path a continuous path in a rectangular area without engaging a bomb in Python

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

Suppose we are given an array mat where the elements are of this form [p, q, r] where p and q are geometric coordinates and r is a radius value. The items in the array are the locations of bombs in a rectangular area of a given width w. The rectangle is infinitely long and is bounded by x coordinates x = 0 to x = w. The r value in the bombs position signifies the safety radius of a bomb, meaning anything less than that radius of the bomb will engage it. So, what we have to do is ...

Read More

Program to find out is a point is reachable from the current position through given points in Python

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

In a 2D space, we have a pointer at position (px, py) that needs to move to destination (qx, qy). The pointer can only move to adjacent cells: (x+1, y), (x-1, y), (x, y+1), or (x, y-1). We're given an array of paths containing intermediate points that must be processed serially. We need to find the minimum number of path points required to reach the destination, or return -1 if unreachable. Problem Example If we have px = 1, py = 1, qx = 2, qy = 3, paths = [[1, 2], [0, 1], [0, 2], [1, 3], ...

Read More
Showing 101–110 of 3,768 articles
« Prev 1 9 10 11 12 13 377 Next »
Advertisements