Print left view of a binary tree
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.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven 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.
This post will detect cycles in a linked list using hashing and Floyd’s cycle detection algorithm.
Find all substrings of a string that contains all characters of another string. In other words, find all substrings of the first string that are anagrams of the second string.
Given a string, find all palindromic permutations of it… We know that the left and right half of a palindrome contains the same set of characters, so any palindromic permutations of a string are only possible if each character’s frequency in the string is even.
Given a string and a positive number k, find the longest substring of the string containing k distinct characters. If k is more than the total number of distinct characters in the string, return the whole string.
Given a list of words, efficiently group all anagrams. The two strings, X and Y, are anagrams if by rearranging X’s letters, we can get Y using all the original letters of X exactly once.
Given a string, find first k non-repeating characters in it by doing only a single traversal of it.
Given a list of words and a pattern, find all words in the list that follows the same order of characters as that of the pattern.