Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 220 of 377

Maximum Number of Ones in C++

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

Suppose we have a matrix M with dimensions w x h, such that every cell has value 0 or 1, and any square sub-matrix of M of size l x l has at most maxOnes number of ones. We have to find the maximum possible number of ones that the matrix M can have.So, if the input is like w = 3, h = 3, l = 2, maxOnes = 1, then the output will be 4 as in a 3*3 matrix, no 2*2 sub-matrix can have more than 1 one. The best solution that has 4 ones is −101000101To ...

Read More

Minimum Time to Build Blocks in C++

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

Suppose we have a list of blocks, if we have blocks[i] = t, this means that the i-th block needs t units of time to be built. A block can only be built by exactly one worker. Single worker can either split into two workers or build a block then go home. These two decisions take some time. The time cost of spliting one worker into two workers is given as a number called split.So, if the input is like blocks = [1, 2], and split = 5, then the output will be 7 as we can split the worker ...

Read More

Divide Chocolate in C++

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

Suppose we have one chocolate bar that consists of some chunks. In each chunk it has its own sweetness given by a list called sweetness. If we want to share the chocolate among K friends so we start cutting the chocolate bar into K+1 piece using K cuts, now each piece consists of some consecutive chunks. If we take out the piece with the minimum total sweetness and give the other pieces to our friends. We have to find the maximum total sweetness of the piece we can get by cutting the chocolate bar optimally.So, if the input is like ...

Read More

Palindrome Removal on C++

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

Suppose we have an integer array called arr, now in one move we can select a palindromic subarray from index i to j where i

Read More

Handshakes That Don't Cross in C++

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

Suppose we have an even number of people n that stand around a circle and each person shakes hands with someone else, so that there will be n / 2 handshakes total. We have to find the number of ways these handshakes could occur such that none of the handshakes cross. The answers may be very large so return the answer mod 10^9 + 7.So, if the input is like n = 2, then the output will be 1To solve this, we will follow these steps −m := 10^9 + 7Define an array dp of size (n+1)dp[0] := 1for initialize i := 0, when i

Read More

Distinct Subsequences in C++

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

Suppose we have strings S and T. We have to count number of distinct sequences of S which is equal to T.We know that a subsequence of a string is a new string which is formed from the original string by removing some (can be none) of the characters without disturbing the relative positions of the remaining characters. (Like, "ACE" is a subsequence of "ABCDE" while "AEC" is not).If the input strings are “baalllloonnn” and “balloon”, then there will be 36 different ways to select.To solve this, we will follow these steps −n := size of s, m := size ...

Read More

Jump Game IV in C++

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

Suppose we have an array of integers called arr. We are initially at index 0. In one step we can jump from index i to i + x where: i + x < n. i - x where: i - x >= 0. j where: arr[i] and arr[j] are same and i and j are not same. Here n is the size of array. We have to find the minimum number of steps to reach the last index of the array.So, if the input is like, then the output will be 3, We need three jumps from index 0 to ...

Read More

Construct Target Array With Multiple Sums in C++

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

Suppose we have an array of integers target. From a starting array A consisting of all 1's, we can perform the following procedure −Consider x be the sum of all elements currently in our array.Choose index i, in range 0 to n, where n is the size of the array and set the value of A at index i to x.We can repeat this procedure as many times as we need.We have to check whether it is possible to make the target array from A otherwise return False.So, if the input is like [3, 9, 5], then the output will ...

Read More

Longest Mountain in Array in C++

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

Consider any (contiguous) subarray B (of A) a called mountain if the following properties hold −size of B >= 3There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1]Suppose we have an array A of integers; we have to find the length of the longest mountain. We have to return 0 if there is no mountain. So if the input is like [2, 1, 4, 7, 3, 2, 5], then the result will be 5. So the largest mountain will be [1, ...

Read More

Count All Valid Pickup and Delivery Options in C++

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

Suppose we have a list of n orders, in each order there are pickup and delivery services. We have to count all valid pickup/delivery possible sequences such that delivery[i] is always after the pickup[i]. As the answer may very large, we will return it modulo 10^9 + 7.So, if the input is like 2, then the output will be 6, as All possible orders are (P1, P2, D1, D2), (P1, P2, D2, D1), (P1, D1, P2, D2), (P2, P1, D1, D2), (P2, P1, D2, D1) and (P2, D2, P1, D1). And the order (P1, D2, P2, D1) is not valid ...

Read More
Showing 2191–2200 of 3,768 articles
« Prev 1 218 219 220 221 222 377 Next »
Advertisements