Find the next node at the same level as the given node in a binary tree
Given a binary tree and a node in it, write an efficient algorithm to find its next node at the same level as the node.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a binary tree and a node in it, write an efficient algorithm to find its next node at the same level as the node.
Given a binary tree, write an efficient algorithm to print its left view. For example, the left view of the following binary tree is 1, 2, 4, 7.
Given a binary tree, write an efficient algorithm to print all nodes in a specific order. We need to print nodes of every level in alternating left and right.
Given a binary tree, print its nodes level by level in reverse order, i.e., print all nodes present at the last level first, followed by nodes of the second last level, and so on… Print nodes at any level from left to right.
Given a binary tree, print its nodes level by level in spiral order, i.e., all nodes present at level 1 should be printed first from left to right, followed by nodes of level 2 right to left, followed by nodes of level 3 from left to right and so on…
Given a binary tree, print its nodes level by level, i.e., print all nodes of level 1 first, followed by nodes of level 2 and so on… Print nodes for any level from left to right.
Given a binary tree, write an efficient algorithm to delete the entire binary tree. The program should deallocate every single node present in the tree, not just change the root node’s reference to null.
Write an efficient algorithm to compute the binary tree’s height. The height or depth is the total number of edges or nodes on the longest path from the root node to the leaf node.
Given an N × N matrix of positive integers, find the shortest path from the first cell of the matrix to its last cell that satisfies given constraints.
Given a binary matrix where 0 represents water and 1 represents land, and connected ones form an island, count the total islands.
Flood fill (also known as seed fill) is an algorithm that determines the area connected to a given node in a multi-dimensional array.
Given a rectangular field with few sensors present, cross it by taking the shortest safe route without activating the sensors.