Arnab Chakraborty has Published 4293 Articles

Number of Islands in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 08:57:19

2K+ Views

Suppose we have a grid, there are few 0s and few 1s. We have to count the number of islands. An island is place that is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. We can assume that all four edges of the grid are ... Read More

Binary Tree Right Side View in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 08:56:19

198 Views

Suppose we have a binary tree, if we see the tree from right side, then we can see some elements of it. we have to display those elements. So if the tree is like −To solve this, we will follow these steps −We will create one helping method for dfs. ... Read More

Binary Search Tree Iterator in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 08:55:04

2K+ Views

Suppose we want to make one iterator for binary tree. There will be two methods. The next() method to return the next element, and hasNext() method to return Boolean value, that will indicate that the next element is present or not. So if the tree is like −And the sequence ... Read More

Maximum Product Subarray in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 08:51:03

1K+ Views

Suppose we have an integer array called nums, we have to find the contiguous subarray within an array (containing at least one number) which has the largest product. So if the array is [2, 3, -2, 4], the output will be 6, as contiguous subarray [2, 3] has max product.To ... Read More

Insertion Sort List in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:42:29

295 Views

Suppose we have a linked list, we have to perform the insertion sort on this list. So if the list is like [9, 45, 23, 71, 80, 55], sorted list is [9, 23, 45, 55, 71, 80].To solve this, we will follow these steps −dummy := new Node with some ... Read More

Binary Tree Preorder Traversal in Python

Arnab Chakraborty

Arnab Chakraborty

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

1K+ Views

Suppose we have a binary tree. We have to return the preorder traversal of that tree. So if the tree is like −Then the preorder traversal will be: [3, 9, 20, 15, 7]To solve this, we will follow these steps −make empty lists called res and st.node := rootwhile node ... Read More

Linked List Cycle II in C++

Arnab Chakraborty

Arnab Chakraborty

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

367 Views

Consider we have a linked list, and we have to check whether there is any cycle or not. To represent the cycle in the given linked list, we will use one integer pointer called pos. This pos represents a position in the linked list where tail is connected. So if ... Read More

Surrounded Regions in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:35:05

313 Views

Suppose we have a 2D board containing X and O. Capture all regions surrounded by X. A region is captured by changing all Os into Xs in that surrounded region.XXXXXOOXXXOXXOXXAfter running the output will beXXXXXXXXXXXXXOXXTo solve this, we will follow these steps −If board is not present, then return blank ... Read More

Path Sum III in C++

Arnab Chakraborty

Arnab Chakraborty

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

269 Views

Suppose we have given a binary tree in which each node holds an integer key. We have to find the paths that sum to a given value. The path should start from root to leaf. We have to find the path where the sum is same.If the tree is like ... Read More

Construct Binary Tree from Inorder and Postorder Traversal in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 06:32:22

246 Views

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

Advertisements