Blog

Top Binary tree interview problems

Here is a curated list of top interview problems on binary trees. These are mostly asked in face to face technical interview rounds. The list contains a wide variety of problems collected from various sources including leetcode, codeforces, codechef, hackerrank and other programming platforms. Practicing these questions would be sufficient enough to brush up your

Continue reading

Construct a BST from preorder traversal

You are given a preorder traversal, you need to construct a binary search tree. Input: {10, 5, 1, 7, 40, 50} is the preorder traversal. Output: 10 / \ 5 40 / \ \ 1 7 50 Algorithm We know that the first element of a preorder traversal if the root of the tree. Leveraging

Continue reading

Left view of a binary tree

You are given a binary tree, you need to print the left view of it. Consider the tree in the below figure. The left view of the tree would be {8, 3, 1, 4}. Algorithm Create a queue which would store the nodes of the tree. Insert the root node in the tree. While the

Continue reading

Path sum equal to k in trees

You are given a binary tree which can have negative elements also and an integer k, you need to print all the paths in the tree which has sum equal to k. Note that the paths need not necessarily be from root to leaf nodes. It can start from any node and can end to

Continue reading

Number of Islands

You are given a 2D grid of 1’s and 0’s where 1’s denotes the land and 0’s denote the water. You need to return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands either vertically or horizontally. You can assume that all the four edges of the

Continue reading

Product of Array except self

You are given an array containing n integers (n>1), you need to return an output array such that output [i] is equal to the product of all the elements of the array except the i’th element. Input: [1, 2, 3, 4] Output: [24, 12, 8, 6] Constraint: You need to solve the problem without using

Continue reading

Loading…

Something went wrong. Please refresh the page and/or try again.


Follow My Blog

Get new content delivered directly to your inbox.