Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 148 of 377

Friends Of Appropriate Ages in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 293 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 548 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 212 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 757 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

Minimum Distance to Type a Word Using Two Fingers in C++

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

Suppose we have a keyboard layout like below −ABCDEFGHIJKLMNOPQRSTUVWXYZWhere each English uppercase letter is located at some coordinate, as an example, the letter A is placed at (0, 0), the letter B is placed at (0, 1), the letter P is placed at (2, 3) and the letter Z is placed at (4, 1). Now if we have a word, we have to find the minimum total distance to type such string using only two fingers. The distance between two places (x1, y1) and (x2, y2) is |x1 - x2| + |y1 - y2|. And we can start from any ...

Read More

Minimum Number of Taps to Open to Water a Garden in C++

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

Suppose there is a one-dimensional garden on the x-axis. The starting position of the garden is 0, and ending position is n. There are n + 1 taps located at points [0, 1, ..., n] in the garden. If we have an integer n and an integer array ranges of length n + 1 where ranges[i] is the i-th tap can water the area [i - ranges[i], i + ranges[i]] when that area is open.We have to find the minimum number of taps that should be open to water the whole garden, if there is no possible solution, then return ...

Read More

Maximal Rectangle in C++

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

Suppose we have a 2D binary matrix where 0s and 1 values are present. We have to find the largest rectangle containing only 1s and return its area.To solve this, we will follow these steps−Define a function called getAns, this will take array acreate stack st, i := 0, ans := 0while i < size of a, thenif stack is empty or a[i] >= top of stack, then insert i into st, increase i by 1otherwise −height := a[top of stack], delete from stackwidth := i when stack is empty, otherwise i – top of st – 1area := height ...

Read More

Interleaving String in C++

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

Suppose we have three strings s1, s2 and s3. Then check whether s3 is formed by interleaving s1 and s2 or not. So if the strings are “aabcc”, s2 = “dbbca”, and s3 is “aadbbcbcac”, then the result will be true.To solve this, we will follow these steps −Define one method called solve(), this will take s1, s2, s3 and one 3d array dp, then i, j, kif i = 0 and j = 0 and k = 0, then return trueif dp[i, j, k] is not -1, then return dp[i, j, k]ans := falseif j > 0 and k ...

Read More

Minimum Difficulty of a Job Schedule in C++

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

Suppose we want to schedule a list of tasks in d days. The tasks are dependent so, to work on the i-th task, we have to finish all the tasks j where 0 0, then −return 1^6if dp[idx, k] is not equal to -1, then −return dp[idx, k]maxVal := 0ret := inffor initialize i := idx, when i < size of v, update (increase i by 1), do −maxVal := maximum of v[i] and maxValret := minimum of ret and maxVal + solve(v, i + 1, k - 1, dp)dp[idx, k] := retreturn retFrom the main method do the ...

Read More

New 21 Game in C++

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

Suppose Rima plays the following game, that is loosely based on the card game "21". So Rima starts with 0 points, and draws numbers while she has less than K points. Now, during each draw, she gains an integer number of points randomly from the range [1, W], where W is given, and that is an integer. Now each draw is independent and the outcomes have equal probabilities. Rima stops drawing numbers when she gets K or more points. We have to find the probability that she has N or less points?So if N = 6, K is 1 and ...

Read More
Showing 1471–1480 of 3,768 articles
« Prev 1 146 147 148 149 150 377 Next »
Advertisements