Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 143 of 377

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 811 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 240 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 × 3 Grid in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 360 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

Word Search II in Python

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

Suppose we have a 2D board and a list of words. So from the dictionary, we have to find all words in the board. Here each word must be constructed from letters of sequentially adjacent cell, where the adjacent cells are those horizontally or vertically neighboring. We have to keep in mind that the same letter cell may not be used more than once in a word.So if the input is like −To solve this, we will follow these steps −make an array resultDefine a method called solve(), this will take board, d, i, j swhen either i or j ...

Read More

Restore The Array in C++

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

Suppose there is a program that is used to print the array elements of an array A, but there was a little mistake in the program. In that program there was no white space after each element, so if we have one printed string, can we regenerate the array again? We know the array elements are in range 1 to k.Given the string s and the integer k. We have to find how many number of ways we can restore the array. The answer may be very large so return it modulo 10^9 + 7.So, if the input is like ...

Read More

Shortest Palindrome in C++

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

Suppose we have a string s. We can convert it to palindrome by adding characters in front of it. We have to find the shortest palindrome, that we can find performing this information. So if the string is like “abcc”, then the result will be − "ccbabcc".To solve this, we will follow these steps −n := size of s, s1 := s, s2 := sReverse the string s2s2 := s concatenate "#" concatenate s2Define an array lps of size same as s2j := 0, i := 1while i < size of s2, do −if s2[i] is same as s2[j], then, ...

Read More

Constrained Subsequence Sum in C++

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

Suppose we have an array called nums and an integer k, we have to find the maximum sum of a non-empty subsequence of that array such that for every two consecutive numbers in the subsequence, nums[i] and nums[j], where i < j, the condition j - i k and first element of dq is same as dp[i - k - 1], thendelete front element from dqdp[i] := maximum of dp[i] and (if dq is empty, then dp[i] + 0, otherwise first element of dp + dq[i])while (not dq is empty and last element of dq < dp[i]), do −delete ...

Read More
Showing 1421–1430 of 3,768 articles
« Prev 1 141 142 143 144 145 377 Next »
Advertisements