Arnab Chakraborty has Published 4293 Articles

Construct Binary Search Tree from Preorder Traversal in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:45:57

804 Views

Suppose we have to create a binary search tree that matches the given preorder traversal. So if the pre-order traversal is like [8, 5, 1, 7, 10, 12], then the output will be [8, 5, 10, 1, 7, null, 12], so the tree will be −To solve this, we will ... Read More

Check If Word Is Valid After Substitutions in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:44:26

341 Views

Suppose we are given that the string "abc" is valid. So from any valid string V, we can divide V into two pieces X and Y such that X + Y is same as V. (X or Y may be empty.). Then, X + "abc" + Y is also valid. ... Read More

Maximum Binary Tree II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:43:36

194 Views

Suppose we have a root node of a maximum tree: The maximum tree is a tree where every node has a value greater than any other value in its subtree. Suppose we have a method called construct(). This can construct a root from a list A. The construct() method is ... Read More

Interval List Intersections in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:36:38

295 Views

Suppose we have two lists of closed intervals, here each list of intervals is pairwise disjoint and in sorted order. We have ti find the intersection of these two interval lists.We know that the closed interval [a, b] is denoted as a A[i][1] or A[i][1] B[j][1] or B[j][1] B[j][1]: ... Read More

Smallest String Starting From Leaf in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:35:23

276 Views

Suppose we have the root of a binary tree, each node is containing a value from 0 to 25 , which are representing the letters 'a' to 'z': a value of 0 represents 'a', a value of 1 represents 'b', and so on. We have to search the lexicographically smallest ... Read More

Minimum Cost For Tickets in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:27:40

489 Views

Suppose there is a country, that is popular for train travel, we have planned some train travelling one year in advance. We have an array, that is holding the days of the year that we will travel. Each day is an integer from 1 to 365. Train tickets are sold ... Read More

Distribute Coins in Binary Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:22:04

228 Views

Suppose we have the root of a binary tree with N nodes, here each node in the tree has node.val number of coins, and there are N coins in total. In one move, we can choose two adjacent nodes and move only one coin from one node to the another ... Read More

Pancake Sorting in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:18:14

644 Views

Suppose we have an array A, we will perform the Pancake sort technique on A. Here the main constraint is that we can use only one operation called rev(arr, i). This will reverse the elements of arr from 0 to ith position. This idea is like the selection sort. We ... Read More

Check Completeness of a Binary Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:17:15

228 Views

Suppose we have a binary tree. We have to check whether the tree is a complete binary tree or not. A complete binary tree of level n, has n-1 complete levels, and all nodes at level n, are filled from the left. So if the input tree is like −Then ... Read More

Flip Equivalent Binary Trees in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 10:11:36

310 Views

Suppose we have a binary tree. We have to flip the binary tree. The flip indicates: choose any node, and swap the left and right child subtrees. Now a binary tree X is flip equivalent to a binary tree Y if and only if we can make Y from X, ... Read More

Advertisements