Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 147 of 377

Trapping Rain Water in Python

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

Suppose we have an array of n non-negative integers. These are representing an elevation map where the width of each bar is 1, we have to compute how much water it is able to trap after raining. So the map will be like −Here we can see there are 6 blue boxes, so the output will be 6.To solve this, we will follow these steps −Define a stack st, water := 0 and i := 0while i < size of heightif is stack is empty or height[stack top] >= height[i], then push i into stack, increase i by 1otherwisex := ...

Read More

Number of Ways to Stay in the Same Place After Some Steps in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 325 Views

Suppose there is an array of size arrLen, and we also have a pointer at index 0 in that array. At each step, we can move 1 position to the left, 1 position to the right in the array or stay in the same place.Now suppose we have two integers steps and arrLen, we have to find the number of ways such that the pointer still at index 0 after exactly steps. If the answer is very large then return it modulo 10^9 + 7.So, if the input is like steps = 3, arrLen = 2, then the output will ...

Read More

Card Flipping Game in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 737 Views

Suppose on a table are N cards, with a positive integer printed on both side of each card (possibly different). We have to flip any number of cards, and after we choose one card. If the number X on the back side of the chosen card is not on the front of any card, then the number X is known as good. We have to find the smallest number that is good? When no number is good, return 0. Here, fronts[i] and backs[i] represent the number on the front and back side of card i. A flip will swap the ...

Read More

Wildcard Matching in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 4K+ Views

Suppose we have an input string s and another input string p. Here is the main string and p is the pattern. We have to define one method, that can match pattern in the string. So we have to implement this for a regular expression, that supports wildcard characters like ‘?’ And ‘*’.Dot ‘?’ Matches any single characterStar ‘*’ Matches zero or more characters.So for example, if the input is like s = “aa” and p = “a?”, then it will be true, for the same input string, if the patter is “?*”, then it will be true.To solve this, ...

Read More

Binary Trees With Factors in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 254 Views

Suppose we have a list of positive integers; whose value is greater than 1. We will make a binary tree, using these integers, and each number may be used as many times as we want. Each non-leaf node should be the product of its children. So we have to find how many trees can we make? The answer will be returned in modulo 10^9 + 7. So if the input is like [2, 4, 5, 10], then the answer will be 7, as we can make 7 trees like [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, ...

Read More

Shortest Path in a Grid with Obstacles Elimination in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 672 Views

Suppose we have a m x n grid, here each cell is either 0 or 1. 0 cell is empty and 1 is blocked. In one step, we can move up, down, left or right from and to an empty cell. We have to find the minimum number of steps to walk from the upper left corner cell (0, 0) to the lower right corner cell (m-1, n-1) given that we can eliminate at most k obstacles. If there is no such way, then return -1.So, if the input is like000110000011000and k is 1, then the output will be 6, ...

Read More

Insert Interval in C++

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

Suppose we have a set of non-overlapping intervals; we have to insert a new interval into the intervals. We can merge if necessary. So if the input is like − [[1, 4], [6, 9]], and new interval is [2, 5], then the output will be [[1, 5], [6, 9]].To solve this, we will follow these steps −Insert new interval at the end of the previous interval listsort the interval list based on the initial time of the intervals, n := number of intervalscreate one array called ans, insert first interval into ansindex := 1while index < n, last := size ...

Read More

Maximum Candies You Can Get from Boxes in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 452 Views

Suppose we have n boxes, here each box is given in the format like [status, candies, keys, containedBoxes] there are some constraints −status[i]: an is 1 when box[i] is open and 0 when box[i] is closed.candies[i]: is the number of candies in box[i].keys[i]: is an array contains the indices of the boxes we can open with the key in box[i].containedBoxes[i]: an array contains the indices of the boxes found in box[i].We will start with some boxes given in initialBoxes array. We can take all the candies in any open box and we can use the keys in it to open ...

Read More

Text Justification in C++

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

Suppose we have an array of words and a width maxWidth, we have to format the text such that each line has exactly maxWidth number of characters and is fully justified. We should pack our words in a greedy approach; so that is, pack as many words as we can in each line. We will pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.Here extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, empty slots on the left ...

Read More

Verbal Arithmetic Puzzle in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 545 Views

Suppose we have an equation, expressions are represented by words on left side and the result on right side. We have to check whether the equation is solvable under the following rules or not −Each character is decoded as one digit (0 to 9).Every pair of different characters must map to different digits.Each words[i] and result are decoded as a number where no leading zeros are present.Sum of numbers on left side will equal to the number on right side.We will check whether the equation is solvable or not.So, if the input is like words = ["SEND", "MORE"], result = ...

Read More
Showing 1461–1470 of 3,768 articles
« Prev 1 145 146 147 148 149 377 Next »
Advertisements