Kth Largest Numbers From Stream - Amazon Top Interview Questions
Implement a data structure with the following methods: KthLargestStream(int[] nums, int k) which constructs the instance. int add(int val) which adds val to nums and returns the k (0-indexed) largest value in nums Constraints 1 ≤ n ≤ 100,000 where n is the length of nums 0 ≤ m ≤ 100,000 where m is the number of calls to add k + 1 ≤ n Example 1 Input methods = ["constructor", "add", "add", "add", "add"] arguments = [[[1, 2, 4, 3], 3], [5], [6], [7], [8]]` Output [None,
View Solution →Kth Smallest in a Binary Search Tree - Amazon Top Interview Questions
Given a binary search tree root, and k return the kth (0-indexed) smallest value in root. It is guaranteed that the tree has at least k + 1 nodes. Constraints k ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [3, [2, null, null], [9, [7, [4, null, null], [8, null, null]], [12, null, null]]] k = 2 Output 4 Example 2 Input root = [3, [2, null, null], [9, [7, [4, null, null], [8, null, null]], [12, null, null]]] k = 0 Output 2
View Solution →Labyrinthian Possibilities - Amazon Top Interview Questions
You are given an N by M matrix of 0s and 1s. Starting from the top left corner, how many ways are there to reach the bottom right corner? Mod the result by 10 ** 9 + 7. You can only move right and down. 0 represents an empty space while 1 represents a wall you cannot walk through. The top left corner and bottom right corner will always be 0. Constraints 1 ≤ n, m ≤ 250 where n and m are the number of rows and columns in matrix. Example 1 Input matrix = [ [0, 0, 1], [0,
View Solution →Largest Sum of Non-Adjacent Numbers - Amazon Top Interview Questions
Given a list of integers nums, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [2, 4, 6, 2, 5] Output 13 Explanation We can take 2, 6, and 5 to get 13. Example 2 Input nums = [5, 1, 1, 5] Output 10 Explanation We can take 5 + 5 since they are not adjacent. Example 3 Input nums = [-10, -22, -18, -3, -100] Out
View Solution →Level Order Traversal - Amazon Top Interview Questions
Given a binary tree root return a level order traversal of the node values. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [5, null, null], [9, [1, [4, null, null], [2, null, null]], [3, null, null]]] Output [0, 5, 9, 1, 3, 4, 2] Example 2 Input root = [0, [1, [2, [3, null, null], null], null], null] Output [0, 1, 2, 3] Example 3 Input root = [0, null, [1, null, [2, null, [3, null, null]]]] Output [0, 1
View Solution →