Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 89 of 377

Program to find area of largest square of 1s in a given matrix in python

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

Suppose we have a binary matrix, we have to find the area of the largest square of 1s in that given matrix using dynamic programming. Problem Understanding Given a binary matrix containing only 0s and 1s, we need to find the area of the largest square submatrix that contains only 1s. For example, if the input matrix is ? .cell { fill: white; stroke: #333; stroke-width: 1; } .one { fill: #4CAF50; } ...

Read More

Program to find largest rectangle area under histogram in python

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

A histogram is a graphical representation where data is displayed using bars of different heights. The largest rectangle area problem asks us to find the maximum rectangular area that can be formed under the histogram bars. Given a list of heights representing histogram bars, we need to find the area of the largest rectangle that fits completely under the bars. Problem Example For the input nums = [3, 2, 5, 7], the histogram looks like: .bar { fill: #4CAF50; stroke: #333; ...

Read More

Program to find minimum swaps required to make given anagram in python

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

Suppose we have two strings S and T and they are anagrams of each other. We have to find the minimum number of swaps required in S to make it same as T. So, if the input is like S = "kolkata" T = "katloka", then the output will be 3, as we can swap in this sequence: [katloka (given), kotlaka, koltaka, kolkata]. Algorithm To solve this, we will follow these steps − Define a function util(). This will take S, T, i if i >= size of S, then return 0 ...

Read More

Program to find nearest number of n where all digits are odd in python

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

Given a number n, we need to find the nearest number where all digits are odd. When two values are equidistant from n, we return the larger one. For example, if the input is n = 243, the output will be 199 because it's the closest number to 243 where all digits (1, 9, 9) are odd. Algorithm To solve this problem, we follow these steps: Find the first even digit from left to right If no even digit exists, return the original number ...

Read More

Program to find maximum difference of adjacent values after deleting k numbers in python

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

Given a sorted list of numbers, we need to delete k values to minimize the maximum difference between adjacent elements. This problem uses dynamic programming to find the optimal solution. Problem Understanding If we have nums = [15, 20, 30, 400, 1500] and k = 2, removing [400, 1500] leaves [15, 20, 30] with maximum adjacent difference of 10 (between 20 and 30). Algorithm Steps The approach follows these steps − Calculate differences between consecutive elements Use dynamic programming to try removing elements from both ends Find the minimum possible maximum difference ...

Read More

Program to find maximum credit we can get by finishing some assignments in python

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

Suppose we have two lists of the same size representing course assignments: deadlines and credits. Here deadlines[i] shows the deadline day for assignment i and credits[i] represents the amount of credits we get for assignment i. We have one day to complete an assignment, and it can be completed before or on the deadline day. We cannot do multiple assignments at the same time. We have to find the maximum credit we can gain by finishing some subset of assignments. So, if the input is like deadlines = [1, 2, 2, 2] and credits = [4, 5, 6, 7], ...

Read More

Program to check number of ways we can move k times and return back to first place in python

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

Suppose we are at position 0 of an n-length array, and on each step, we can move right one place, left one place (not exceeding bounds), or stay at the same position. We need to find how many unique walks of exactly k steps return us back to index 0. If the answer is very large, return it modulo 10^9 + 7. So, if the input is like n = 7, k = 4, then the output will be 9. The possible action sequences are ? [Right, Right, Left, Left] [Right, Left, Right, Left] [Stay, Stay, Stay, ...

Read More

Program to find number of steps to solve 8-puzzle in python

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

The 8-puzzle is a classic sliding puzzle game where you have a 3x3 grid with numbers 0-8, and you need to arrange them in order by sliding tiles into the empty space (represented by 0). This problem asks us to find the minimum number of steps to solve the puzzle using a breadth-first search approach. Understanding the Problem Given a 3x3 board with numbers 0-8 (no duplicates), we can swap the 0 with any of its adjacent neighbors. The goal is to arrange the numbers in sequential order from 0 to 8. For example, if we have ...

Read More

Program to check whether we can form 24 by placing operators in python

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

Suppose we have a list of four numbers, each number is in range 1 to 9, in a fixed order. We need to place operators (+, -, *, /) between the numbers and group them with brackets to check whether it is possible to get the value 24 or not. So, if the input is like nums = [5, 3, 6, 8, 7], then the output will be True, as (5 * 3) - 6 + (8 + 7) = 24. Approach We will use a recursive approach to generate all possible results by splitting the array ...

Read More

Program to find number of days it will take to burn all trees in python

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

Suppose we have a 2D matrix that represents a forest where there are three types of cells: 0 (empty cell), 1 (tree cell), and 2 (tree on fire cell). Every day, a tree catches fire when there is an adjacent (top, down, left, right, not diagonal) tree on fire. We have to find the number of days it would take for every tree to be on fire. If that is not possible, return -1. Problem Example If the input matrix is: 1 2 1 1 0 1 1 1 1 ...

Read More
Showing 881–890 of 3,768 articles
« Prev 1 87 88 89 90 91 377 Next »
Advertisements