title-img


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 →

First Missing Positive - Amazon Top Interview Questions

Given a list of integers nums, find the first missing positive integer. In other words, find the lowest positive integer that does not exist in the list. The list can contain duplicates and negative numbers as well. Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [1, 2, 3] Output 4 Example 2 Input nums = [3, 4, -1, 1] Output 2 Example 3 Input nums = [1, 2, 0] Output 3 Example 4 Input nums = [-1, -2, -3]

View Solution →

Height Balanced Tree - Amazon Top Interview Questions

Given the root of a binary tree, return whether its height is balanced. That is, for every node in the tree, the absolute difference of the height of its left subtree and the height of its right subtree is 0 or 1. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, null, [4, null, [12, null, null]]] Output False Explanation This is false since the root's right subtree has height of 2, and left has height of 0. Example 2 Input

View Solution →

Inorder Traversal - Amazon Top Interview Questions

Given a binary tree root, return an inorder traversal of root as a list. Bonus: Can you do this iteratively? Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, null, [159, [80, null, null], null]] Output [1, 80, 159]

View Solution →