title-img


Lowest Common Ancestor - Amazon Top Interview Questions

Given a binary tree root, and integers a and b, find the value of the lowest node that has a and b as descendants. A node can be a descendant of itself. All nodes in the tree are guaranteed to be unique. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [1, null, null], [2, [6, [3, null, null], [4, null, null]], [5, null, null]]] a = 3 b = 5 Output 2 Example 2 Input root = [0, [1, null, null], [2, [6, [3, null, null],

View Solution →

Lowest Common Ancestor of List of Values - Amazon Top Interview Questions

Given a binary tree root containing unique values and a list of unique integers values, return the lowest common ancestor node that contains all values in values. You can assume that a solution exists. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [2, null, null], [3, [4, [6, null, null], [7, null, null]], [5, null, null]]] values = [5, 6, 7] Output [3, [4, [6, null, null], [7, null, null]], [5, null, null]]

View Solution →

Making Change - Amazon Top Interview Questions

Find the minimum number of coins required to make n cents. You can use standard American denominations, that is, 1¢, 5¢, 10¢, and 25¢. Constraints 0 ≤ n < 2 ** 31 Example 1 Input n = 3 Output 3 Explanation You can make this with 3 pennies. Example 2 Input n = 5 Output 1 Explanation You can make this with a 5 cent coin. Example 3 Input n = 6 Output 2 Explanation You can make this with a 5 cent coin and a 1 cent coin.

View Solution →

Matrix Search Sequel - Amazon Top Interview Questions

Given a two-dimensional integer matrix, where every row and column is sorted in ascending order, return whether an integer target exists in the matrix. This should be done in \mathcal{O}(n + m)O(n+m) time. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 3, 9], [2, 5, 10], [5, 7, 13] ] target = 7 Output True

View Solution →

Number of Hops - Amazon Top Interview Questions

Given an integer list nums where each number represents the maximum number of hops you can make, return the minimum number of hops it would take to reach the last index starting at index 0. You can assume that you can always reach the last index. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [3, 3, 2, 0, 1] Output 2 Explanation We can jump from index 0 to 1 and then jump straight to the last index by jumping 3 steps.

View Solution →