Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 241 of 377

Binary Trees With Factors in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 262 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 690 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 470 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 557 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

Friends Of Appropriate Ages in C++

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

Suppose some people will make friend requests. We know their ages, these are stored in ages[i]. So this indicates that the age of the ith person. Now a A will NOT friend request person B (B != A) if any of the following conditions are true −age[B] age[A]age[B] > 100 && age[A] < 100Otherwise, A will friend request B. You can consider that if A requests B, B does not necessarily request A. And also, people will not friend request themselves. So we have to find how many total friend requests are made?Suppose if the age array is like ...

Read More

Edit Distance in C++

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

Suppose we have two words word1 and word2, we have to find the minimum number of operations required to concert from word1 to word2. The operations can be of three types, these are insert a character, delete a character and replace a character. So if the input strings are “evaluate” and “fluctuate”, then the result will be 5.To solve this, we will follow these steps −n := size of w1, m := size of w2, create an array dp of size n + 1for i in range 0 to ndp[i] := new array of size m + 1for j in ...

Read More

Distinct Echo Substrings in C++

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

Suppose we have a string S; we have to find the number of distinct non-empty substrings of S that can be written as the concatenation of some string with itself.So, if the input is like "elloelloello", then the output will be 5, as there are some substrings like "ello", "lloe", "loel", "oell".To solve this, we will follow these steps −prime := 31m := 1^9 + 7Define a function fastPow(), this will take base, power, res := 1while power > 0, do −if power & 1 is non-zero, then −res := res * baseres := res mod mbase := base * ...

Read More

Minimum Window Substring in C++

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

Suppose we have a string S and T. We have to find the minimum window in S which will contain all the characters in T. So if the input is like “ABHDAXCVBAGTXATYCB” and T = “ABC”, then the result will be: “CVBA”.To solve this, we will follow these steps −Create one map mstore the frequency of x into mlength := size of s, left := 0, right := 0, ansLeft := 0 and ansRight := 0counter := size of x, flag := false, ans := empty stringwhile height < size of s −c := s[right]if c is present in m, ...

Read More
Showing 2401–2410 of 3,768 articles
« Prev 1 239 240 241 242 243 377 Next »
Advertisements