title-img


Complete Binary Tree - Amazon Top Interview Questions

Given a binary tree root, return whether it's a complete binary tree. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [1, [1, null, null], [0, null, null]], [0, [1, null, null], [0, null, null]]] Output True Example 2 Input root = [0, [1, [1, null, null], [0, null, null]], [0, null, null]] Output True Example 3 Input root = [0, [1, null, [0, null, null]], [0, null, null]] Output False

View Solution →

Delete Sublist to Make Sum Divisible By K - Amazon Top Interview Questions

You are given a list of positive integers nums and a positive integer k. Return the length of the shortest sublist (can be empty sublist ) you can delete such that the resulting list's sum is divisible by k. You cannot delete the entire list. If it's not possible, return -1. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 8, 6, 4, 5] k = 7 Output 2 Explanation We can remove the sublist [6, 4] to get [1, 8, 5] which sums to 14 and

View Solution →

Earliest Uniques in a Stream - Amazon Top Interview Questions

Implement a data structure with the following methods: EarliestUnique(int[] nums) constructs a new instance with the given list of numbers. add(int num) adds num to the data structure. firstUnique() returns the first unique number. If there's no unique number, return -1. Constraints n ≤ 100,000 where n is the number of calls to add and firstUnique. Example 1 Input methods = ["constructor", "add", "earliestUnique", "add", "earliestUnique"] arguments = [[[1, 2, 3]], [1], [], [

View Solution →

Edit Distance - Amazon Top Interview Questions

Given two strings a and b, find the minimum edit distance between the two. One edit distance is defined as Deleting a character or Inserting a character or Replacing a character Constraints n ≤ 1,000 where n is the length of a m ≤ 1,000 where m is the length of b Example 1 Input a = "zhello" b = "helli" Output 2 Explanation "z" is removed and the "o" is replaced with "i" Example 2 Input a = "dycare" b = "daycare" Output 1 Explanation "a"

View Solution →

Enlarge BST - Amazon Top Interview Questions

Given a binary search tree root, replace every node's value v by its value plus the sum of all other values in the tree that are greater than v. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [4, [2, [1, null, null], [3, null, null]], [5, null, null]] Output [9, [14, [15, null, null], [12, null, null]], [5, null, null]]

View Solution →