Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 140 of 377

Subarrays with K Different Integers in C++

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

Suppose we have an array A of positive integers, we can call a good subarray (contiguous) of A, if the number of different integers in that subarray is exactly K. So, if the array is like [1, 2, 3, 1, 2] has 3 different integers: 1, 2, and 3. We have to find the number of good subarrays of A.So, if the input is like [1, 2, 3, 1, 4] and K = 3, then the output will be 4, as it can form three subarrays with exactly four distinct integers, these are [1, 2, 3], [1, 2, 3, 1], ...

Read More

Number of Squareful Arrays in C++

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

Suppose we have an array A of positive integers, we can say that array is squareful if for every pair of adjacent elements, their sum is a perfect square. We have to find the number of permutations of A that are squareful. Two permutations A1 and A2 will not be same if and only if there is some index i such that A1[i] not same as A2[i].So, if the input is like [3, 30, 6], then the output will be 2, as we have two permutations like [3, 6, 30], [30, 6, 3].To solve this, we will follow these steps ...

Read More

Minimum Cost to Merge Stones in C++

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

Suppose we have N piles of stones arranged in a row. Here the i-th pile has stones[i] number of stones. A move consists of merging K consecutive piles into one pile, now the cost of this move is equal to the total number of stones in these K number of piles. We have to find the minimum cost to merge all piles of stones into one pile. If there is no such solution then, return -1.So, if the input is like [3, 2, 4, 1] and K = 2, then the output will be 20, this is because, we will ...

Read More

Numbers With Repeated Digits in C++

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

Suppose we have a positive integer N, we have to find the number of positive integers less than or equal to N that have at least 1 repeated digit .So, if the input is like 99, then the output will be 9, as we have numbers like 11, 22, 33, 44, 55, 66, 77, 88, 99.To solve this, we will follow these steps −Define a function A(), this will take m, n, ret := 1for initialize i := 0, when i < n, update (increase i by 1), do −ret := ret * m(decrease m by 1)return retFrom the main ...

Read More

Construct String from Binary Tree in Python

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

Suppose we have a binary tree we have to make a string consists of parenthesis and integers from a binary tree with the preorder traversing way. A null node will be represented by empty parenthesis pair "()". And we need to omit all the empty parenthesis pairs that don't affect the one-to-one mapping relationship between the string and the original binary tree.So, if the input is likethen the output will be 5(6()(8))(7)To solve this, we will follow these steps −ans := blank stringDefine a function pot(). This will take node, sif is null, thenreturn blank stringif if left or right ...

Read More

Longest Duplicate Substring in C++

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

Suppose we have a string S, consider all duplicated contiguous substrings that occur 2 or more times. (The occurrences may overlap.), We have to find the duplicated substring that has the longest possible length. If there is no such substrings, then return a blank string. As the answer may very large, so return in mod 10^9 + 7.So, if the input is like "ababbaba", then the output will be "bab"To solve this, we will follow these steps −m := 1e9 + 7Define a function add(), this will take a, b, return ((a mod m) + (b mod m)) mod mDefine ...

Read More

Second Minimum Node In a Binary Tree in C++

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

Suppose there is a non-empty special binary tree with some non-negative value, here each node in this tree has exactly two or zero children. If the node has two children, then this node's value is the smaller value among its two children. In other words, we can say that [root.val = minimum of root.left.val, root.right.val]. If we have such binary tree, we have to find the second minimum value in the set made of all the nodes' value in the whole tree. If there is no such element, then return -1 instead.So, if the input is likethen the output will ...

Read More

Number of Submatrices That Sum to Target in C++

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

Suppose we have a matrix, and a target value, we have to find the number of non-empty submatrices that sum is same as target. Here a submatrix [(x1, y1), (x2, y2)] is the set of all cells matrix[x][y] with x in range x1 and x2 and y in range y1 and y2. Two submatrices [(x1, y1), (x2, y2)] and [(x1', y1'), (x2', y2')] are different if they have some coordinate that is different: like, if x1 is not same as x1'.So, if the input is like010111010and target = 0, then the output will be 4, this is because four 1x1 ...

Read More

Longest Continuous Increasing Subsequence in C++

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

Suppose we have an array of integers; we have to find the length of longest continuous increasing subarray.So, if the input is like [2,4,6,5,8], then the output will be 3. As the longest continuous increasing subsequence is [2,4,6], and its length is 3.To solve this, we will follow these steps −if size of nums

Read More

Parsing A Boolean Expression in Python

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

Suppose we have a boolean expression, we have to find the result after evaluating that expression.An expression can either be −"t", evaluating to True;"f", evaluating to False;"!(expression)", evaluating to the logical NOT of the inner expression;"&(expr1, expr2, ...)", evaluating to the logical AND of 2 or more inner expressions;"|(expr1, expr2, ...)", evaluating to the logical OR of 2 or more inner expressions;So, if the input is like "|(!(t), &(t, f, t))", then the output will be fasle, this is because !(t) is false, then &(t, f, t) is also false, so the OR of all false values will be false.To ...

Read More
Showing 1391–1400 of 3,768 articles
« Prev 1 138 139 140 141 142 377 Next »
Advertisements