Merging Binary Trees - Amazon Top Interview Questions
Given two binary trees node0 and node1, return a merge of the two trees where each value is equal to the sum of the values of the corresponding nodes of the input trees. If only one input tree has a node in a given position, the corresponding node in the new tree should match that input node. Constraints n ≤ 100,000 where n is the number of nodes in node0 m ≤ 100,000 where m is the number of nodes in node1 Example 1 Input node0 = [0, [3, null, null], [2, [3, null, null], null]]
View Solution →Sum of Two Numbers in BSTs - Amazon Top Interview Questions
You are given two binary search trees a and b and an integer target. Return whether there's a number in a and a number in b such that their sum equals to target Constraints n ≤ 100,000 where n is the number of nodes in a m ≤ 100,000 where m is the number of nodes in b Example 1 Input a = [5, [3, null, null], [7, null, null]] b = [4, [2, null, null], [8, null, null]] target = 9 Output True Explanation We can pick 7 from a and 2 from b. Example 2 Input a =
View Solution →Postfix Notation Evaluation - Amazon Top Interview Questions
Postfix notation is a way to represent an expression where the operator comes after the operands. For example, ["2", "2", "+", "6", "*"] would be equal to 24, since we have (2 + 2) * 6 = 24. Given a list of strings exp, representing a postfix notation consisting of integers and operators ("+", "-", "*", "/"), evaluate the expression. "/" is integer division. Example 1 Input exp = ["9", "3", "+", "2", "/"] Output 6 Explanation (9 + 3) / 2 = 6 Example 2 Input
View Solution →Space Battle - Amazon Top Interview Questions
There are a bunch of rockets in space lined up in a row. You are given a list of integers nums representing each rocket's size and direction. If the number is positive it's going right, and if it's negative it's going left. The value of the number represents the rocket's size. If two rockets collide, the smaller one will disappear and the larger one will continue on its course unchanged. If they are the same size and they collide, they'll both explode (both numbers are removed). If two roc
View Solution →List Partitioning - Amazon Top Interview Questions
Given a list of strings strs, containing the strings "red", "green" and "blue", partition the list so that the red come before green, which come before blue. This should be done in \mathcal{O}(n)O(n) time. Bonus: Can you do it in \mathcal{O}(1)O(1) space? That is, can you do it by only rearranging the list (i.e. without creating any new strings)? Constraints n ≤ 100,000 where n is the length of strs. Example 1 Input strs = ["green", "blue", "red", "red"] Output ["red
View Solution →