Arnab Chakraborty has Published 4293 Articles

Longest Consecutive Sequence in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 13:10:25

5K+ Views

Suppose we have an array of integers. We have to find the length of the longest consecutive elements sequence. So if the input is like [100, 4, 250, 1, 3, 2], answer will be 4, as the longest consecutive sequence is [1, 2, 3, 4].To solve this, we will follow ... Read More

Binary Tree Maximum Path Sum in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 13:07:57

932 Views

Suppose we have one non-empty binary tree. We have to find the path sum. So here, a path is any sequence of nodes from some starting node to any node in the where the parent-child connections are present. The path must contain at least one node and does not need ... Read More

Distinct Subsequences in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 12:59:27

197 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 ... Read More

Recover Binary Search Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 12:56:38

338 Views

Suppose we have one binary search tree, now consider two elements of this BST is swapped, so we have to recover this binary search tree.So if the given tree is like below (first one), the recovered tree will be (second one) −To solve this, we will follow these steps −Define ... Read More

Interleaving String in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 12:50:30

492 Views

Suppose we have three strings s1, s2 and s3. Then check whether s3 is formed by interleaving s1 and s2 or not. So if the strings are “aabcc”, s2 = “dbbca”, and s3 is “aadbbcbcac”, then the result will be true.To solve this, we will follow these steps −Define one ... Read More

Maximal Rectangle in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 12:46:33

427 Views

Suppose we have a 2D binary matrix where 0s and 1 values are present. We have to find the largest rectangle containing only 1s and return its area.To solve this, we will follow these steps−Define a function called getAns, this will take array acreate stack st, i := 0, ans ... Read More

Minimum Window Substring in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 12:27:46

680 Views

Suppose we have a string S and T. We have to find the minimum window in S which will contain all the characters in T. So if the input is like “ABHDAXCVBAGTXATYCB” and T = “ABC”, then the result will be: “CVBA”.To solve this, we will follow these steps −Create ... Read More

Edit Distance in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 12:24:03

503 Views

Suppose we have two words word1 and word2, we have to find the minimum number of operations required to concert from word1 to word2. The operations can be of three types, these are insert a character, delete a character and replace a character. So if the input strings are “evaluate” ... Read More

Text Justification in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 12:18:51

2K+ Views

Suppose we have an array of words and a width maxWidth, we have to format the text such that each line has exactly maxWidth number of characters and is fully justified. We should pack our words in a greedy approach; so that is, pack as many words as we can ... Read More

Insert Interval in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 26-May-2020 12:08:42

2K+ Views

Suppose we have a set of non-overlapping intervals; we have to insert a new interval into the intervals. We can merge if necessary. So if the input is like − [[1, 4], [6, 9]], and new interval is [2, 5], then the output will be [[1, 5], [6, 9]].To solve ... Read More

Advertisements