Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 127 of 377

Max Points on a Line in C++

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

Suppose we have a 2D plane. We have to find the maximum number of points that reside on the same straight line. So if the points are like −Then there are 4 pointsTo solve this, we will follow these steps −n := number of points, if n < 3, then return nans := 2for i in range 1 to n – 1count := 0take two points from index i and i – 1, these are p1, p2if p1 and p2 points are same, thenfor j in range 0 to n – 1if points[j].x = p1.x and points[j].y = p1.y, then ...

Read More

Longest Happy Prefix in C++

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

Suppose we have a string s, we have to find the longest happy prefix of s. A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself). If there is no such happy prefix, then simply return blank string.So, if the input is like "madam", then the output will be "m", it has 4 prefixes excluding itself. These are "m", "ma", "mad", "mada" and 4 suffixes like "m", "am", "dam", "adam". The largest prefix which is also suffix is given by "m".To solve this, we will follow these steps −Define a function ...

Read More

Score of Parentheses in C++

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

Suppose we have a balanced parentheses string S, we have to compute the score of the string based on the following rule −The () has score 1AB has score A + B, where A and B are two balanced parentheses strings.(A) has score 2 * A, where A is a balanced parentheses string.So if the input is like “(()(()))”, then the output will be 6.To solve this, we will follow these steps −ans := 0, define a stack stfor i in range 0 to size of string Sif S[i] is opening parentheses, then insert -1 into stackotherwiseif top of stack ...

Read More

Find All Good Strings in C++

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

Suppose we have two strings s1 and s2. The size of these strings is n, and we also have another string called evil. We have to find the number of good strings.A string is called good when its size is n, it is alphabetically greater than or equal to s1, it is alphabetically smaller than or equal to s2, and it has no evil as a substring. The answer may be very large, so return the answer modulo 10^9 + 7.So, if the input is like n = 2, s1 = "bb", s2 = "db", evil = "a", then the ...

Read More

Mirror Reflection in C++

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

Suppose there is a special square room with mirrors on each of the four walls. In each corner except the southwest corner, there are receptors. These are numbered as 0, 1, and 2. Now the square room has walls of length p, and a laser ray from the southwest corner first meets the east wall at a distance q from the 0th receptor. We have to find the number of the receptor that the ray meets first.So if p = 2, and q = 1, then the case will be like −So the output will be 2, as the ray ...

Read More

Reducing Dishes in C++

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

Suppose there is a chef. And he has collected data on the satisfaction level of his n dishes. The Chef can cook any dish in 1 unit of time. Like-time coefficient of a dish is actually the time takento cook that dish including previous dishes multiplied by its satisfaction level So time[i]*satisfaction[i].We have to find the maximum sum of Like-time coefficient that the chef can obtain after dishes preparation. Dishes can be ready in any order and the chef can discard some dishes to get this maximum value.So, if the input is like [-1, -7, 0, 6, -7], then the ...

Read More

Dungeon Game in C++

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

Suppose there is a story like the demons had captured the princess whose name is P and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M row, N column grid-like rooms. Our valiant knight named K was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess.Now the knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies at that moment.Some of the rooms have demons to guard that room, so the ...

Read More

Stone Game III in C++

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

Suppose Amal and Bimal are playing with piles of stones. There are several stones arranged in a row, and each stone has an associated value which is a number given in the array called stoneValue.Amal and Bimal take turns, with Amal starting first. On each player's turn, he/she can take 1, 2 or 3 stones from the first remaining stones in the row.The score of each player is the sum of values of the stones taken. Initially the score is 0. The goal of the game is to end with the highest score, and the winner is the player with ...

Read More

Best Time to Buy and Sell Stock IV in C++

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

Suppose we have an array for which the i-th element is the price of a given stock for the day i. We have to devise an algorithm to find the maximum profit. We can complete at most k transactions. So if the input is like [3, 2, 6, 4, 0, 3] and k = 2, then the output will be 7, as buy on day 2 (when price = 2) and sell on day 3 (when price = 6), profit will be 6-2 = 4. Then buy on day 5 (price is 0) and sell on day 6 (price is ...

Read More

Number of Ways to Paint N &times; 3 Grid in C++

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

Suppose we have grid of size n x 3 and we want to paint each cell of the grid with exactly one of the three colors. The colors are Red, Yellow or Green. Now there is a constraint that is no two adjacent cells have the same color. We have n the number of rows of the grid. We have to find the number of ways we can paint this grid. The answer may be very large so return it modulo 10^9 + 7.So, if the input is like 1, then the output will be 12To solve this, we will ...

Read More
Showing 1261–1270 of 3,768 articles
« Prev 1 125 126 127 128 129 377 Next »
Advertisements