Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 126 of 377

Maximum Sum BST in Binary Tree in C++

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

Suppose we have a binary tree root, we have to find the maximum sum of all nodes of any subtree which is also a Binary Search Tree (BST).So, if the input is like, then the output will be 20, this is the sum of all nodes in the selected BST.To solve this, we will follow these steps −Create one block called Data, this will hold some members like sz, maxVal, minVal, ok, sum. Also define one initializer for data, that will take in this order (sz, minVal, maxVal, ok, and set sum as 0)ret := 0Define a method called solve(), ...

Read More

Hand of Straights in C++

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

Suppose Rima has a hand of cards, given as an array of integers. Now she wants to shuffle the cards into groups so that each group is size W, and consists of W consecutive cards. We have to check whether it is possible or not.So if the cards are [1, 2, 3, 6, 2, 3, 4, 7, 8], and W = 3, then the answer will be true, as she can rearrange them like [1, 2, 3], [2, 3, 4], [6, 7, 8]To solve this, we will follow these steps −Define a map m, and store frequency of each element ...

Read More

Candy in C++

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

Suppose there are N children, they are standing in a line. Here each child is assigned a rating value. We are supplying candies to these children subjected to the following requirements −Each child must have at least one candy.Children whose rating is high will get more candies than their neighbors.We have to find the minimum number of candies we must give?So if the input is like [1, 1, 3], then the output will be 4. So they will get 1, 1 and 2 candies respectively.To solve this, we will follow these steps −n := size of the array ratings, create ...

Read More

Frog Position After T Seconds in C++

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

Suppose we have one undirected tree consisting of n vertices. The vertices are numbered from 1 to n. Now a frog starts jumping from the vertex 1. The frog can jump from its current vertex to another non-visited vertex if they are adjacent, in one second. The frog can not jump back to a visited vertex. In case the frog can jump to several vertices it jumps randomly to one of themwhere the probability is same, otherwise, when the frog can not jump to any non-visited vertex it jumps forever on the same vertex.The tree is given as an array ...

Read More

Word Break II in Python

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

Suppose we have a non-empty string s and a dictionary called wordDict, this dictionary is containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. We have to find all such possible sentences. “appleraincoat” and dictionary is [“app”, “apple”, “rain”, “coat”, “raincoat”]To solve this, we will follow these steps −Create one map memoDefine a method called solve, this will take string and wordDictif s is null, then return empty listif s in memo, then −return memo[s]create an array retfor i in range 1 to size of sif substring ...

Read More

Maximum Performance of a Team in C++

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

Suppose there are n engineers. They are numbered from 1 to n and we also have two arrays: speed and efficiency, here speed[i] and efficiency[i] represent the speed and efficiency for the ith engineer. We have to find the maximum performance of a team composed of at most k engineers. The answer may be very large so return it modulo 10^9 + 7.Here the performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers.So, if the input is like n = 6, speed = [1, 5, 8, 2, 10, 3], efficiency ...

Read More

Shifting Letters in C++

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

Suppose we have a string S of lowercase letters, and an integer array shifts. The shift of a letter means the next letter in the alphabet, for z, it will be a. Now for each shifts[i] = x, we want to shift the first i+1 letters of S, x times. We have to find the final string after all such shifts to S are applied. So if the string is “abc” and shifts = [3, 5, 9], then after shifting the first 1 letter of S by 3, will have “dbc”, shifting first two letters of S by 5, we ...

Read More

Binary Tree Postorder Traversal in Python

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

Suppose we have a binary tree. We have to find the post order traversal of this tree using the iterative approach. So if the tree is like −Then the output will be: [9, 15, 7, 10, -10]To solve this, we will follow these steps −if root is null, then return empty arraycreate an array retstack := define a stack with pair [root, 0]while stack is not empty −node := top of stack, then delete element from stack.if second value of node pair is 0, thencurrent := first value of node pairinsert a pair (current, 1) into stackif right of current ...

Read More

Pizza With 3n Slices in C++

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

Suppose there is a pizza with 3n slices of varying size, I and my two friends will take slices of pizza as follows −I shall pick any pizza slice.My friend Amal will pick next slice in anti clockwise direction of my pick.My friend Bimal will pick next slice in clockwise direction of my pick.Repeat these steps until there are no more slices of pizzas.Sizes of Pizza slices is represented by circular array slices in clockwise direction. We have to find the maximum possible sum of slice sizes which I can have.So, if the input is like [9, 8, 6, 1, ...

Read More

Car Fleet in C++

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

Suppose there are N cars that are going to the same destination along a one lane road. The destination is ‘target’ miles away. Now each car i has a constant speed value speed[i] (in miles per hour), and initial position is position[i] miles towards the target along the road.A car can never pass another car ahead of it, but it can catch up to it, and drive bumper to bumper at the same speed. Here the distance between these two cars is ignored - they are assumed to have the same position. A car fleet is some non-empty set of ...

Read More
Showing 1251–1260 of 3,768 articles
« Prev 1 124 125 126 127 128 377 Next »
Advertisements