title-img


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 →

Fair Pay - Amazon Top Interview Questions

You are given a list of integers ratings representing the performance scores of programmers. The manager would like to give $1 to every programmer except if two programmers are adjacent, they'd like to pay the better performing programmer at least $1 higher than the worse performing one. Return the minimum amount of dollars the manager can pay following above constraints. Constraints n ≤ 100,000 where n is the length of ratings. Example 1 Input ratings = [1, 2, 5, 1] Output

View Solution →

Find the Largest Number in a Rotated List - Amazon Top Interview Questions

You are given a list of unique integers nums that is sorted in ascending order and is rotated at some pivot point. Find the maximum number in the rotated list. Can you solve it in \mathcal{O}(\log{}n)O(logn)? Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input arr = [6, 7, 8, 1, 4] Output 8 Explanation The original sorted array of [1, 4, 6, 7, 8] was rotated at index 2 and results in the input array [6, 7, 8, 1, 4,]. And the largest number is 8.

View Solution →