Arnab Chakraborty has Published 4293 Articles

Construct Binary Tree from Preorder and Inorder Traversal in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:27:14

1K+ Views

Suppose we have the inorder and preorder traversal sequence of a binary tree. We have to generate the tree from these sequences. So if the preorder and inorder sequences are [3, 9, 20, 15, 7] and [9, 3, 15, 20, 7], then the tree will be −Let us see the ... Read More

Reverse Linked List II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:24:06

259 Views

Suppose we have a linked list. We have to reverse the nodes from position m to n. We have to do it in one pass. So if the list is [1, 2, 3, 4, 5] and m = 2 and n = 4, then the result will be [1, 4, ... Read More

Subsets II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:23:09

433 Views

Suppose we have a set of numbers; we have to generate all possible subsets of that set. This is also known as power set. We have to keep in mind that the elements may be duplicate. So if the set is like [1, 2, 2], then the power set will ... Read More

Remove Duplicates from Sorted List II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:21:19

300 Views

Suppose we have a list of some elements. We have to remove all elements that have occurred more than once. So only the distinct elements will remain in the list. So if the list is like [1, 1, 1, 2, 2, 3, 5, 6, 6, 7, 8], then the output ... Read More

Search in Rotated Sorted Array II in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:19:34

310 Views

Consider we have an array sorted in ascending order. That is rotated at some pivot unknown to us beforehand. For example, if the array is like [0, 0, 1, 2, 2, 5, 6], this might become [2, 5, 6, 0, 0, 1, 2]. We have a target value to search. ... Read More

Remove Duplicates from Sorted Array II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:17:59

2K+ Views

Suppose we have a sorted array nums, we have to remove the duplicates in-place such that duplicates elements will appear at most twice and return the new length. To do this task we cannot take extra space. We have to solve this with O(1) amount of space. For example, if ... Read More

Subsets in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:14:43

1K+ Views

Suppose we have a set of numbers; we have to generate all possible subsets of that set. This is also known as power set. So if the set is like [1, 2, 3], then the power set will be [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, ... Read More

Search a 2D Matrix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:13:31

423 Views

Suppose we have write an efficient algorithm to searches for a value in one m x n matrix. This matrix has some properties like below −Each row is sorted from left to rightThe first number of each row is greater than the last integer of the previous row.So if the ... Read More

Set Matrix Zeroes in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:09:38

2K+ Views

Consider we have a matrix, in that matrix if one element is 0, then make the entire row and column of that matrix to 0. The conversion will be in-place. So if the matrix is −101111111Then the output will be −000101101Let us see the steps −n := number of rows, ... Read More

Simplify Path in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:08:30

1K+ Views

Suppose we have an absolute path for a file (Like Unix File system), we have to simplify it. Or in other words, we have to convert it to the canonical path. In the UNIX-style file system, a period ‘.’ refers to the current directory. And a double period ‘..’ moves ... Read More

Advertisements