title-img


Second Place - Amazon Top Interview Questions

Given a binary tree root, return the depth of the second deepest leaf. Note that if there are multiple deepest leaves, the second deepest leaf is the next highest one. The root has a depth of 0 and you can assume the answer is guaranteed to exist for the trees given. 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], null], [5, null, [7, null, null]]]] Output 1 Explanation The the seco

View Solution →

Smallest Intersecting Element - Amazon Top Interview Questions

You are given a two-dimensional list of integers matrix where each row is sorted in ascending order. Return the smallest number that exists in every row. If there's no solution, return -1. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 2, 4], [4, 9, 9], [0, 2, 4] ] Output 4

View Solution →

Sort by Frequency and Value - Amazon Top Interview Questions

Given a list of integers nums, order nums by frequency, with most frequent values coming first. If there's a tie in frequency, higher valued numbers should come first. Constraints 0 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 1, 5, 5, 5, 2, 2, 2, 1, 1] Output [1, 1, 1, 1, 5, 5, 5, 2, 2, 2] Explanation Since 1 occurs most frequently (4 times) they come first. 5 and 2 are then tied in terms of frequency (both 3 times) but 5 has higher value s

View Solution →

Special Product List - Amazon Top Interview Questions

Given a list of integers nums, return a new list such that each element at index i of the new list is the product of all the numbers in the original list except the one at i. Do this without using division. Constraints 2 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 2, 3, 4, 5] Output [120, 60, 40, 30, 24] Explanation 120 = 2 * 3 * 4 * 5, 60 = 1 * 3 * 4 * 5, and so on. Example 2 Input nums = [3, 2, 1] Output [2, 3, 6]

View Solution →

Sudoku Solver - Amazon Top Interview Questions

Sudoku is a puzzle where you're given a partially-filled 9 by 9 grid with digits. The objective is to fill the grid with the constraint that every row, column, and box (3 by 3 subgrid) must contain all of the digits from 1 to 9. Implement an efficient sudoku solver that takes in an incomplete board and solves it. In the given board, the incomplete spaces will be 0. Constraints n = 9 where n is the number of rows and columns in matrix Example 1 Input matrix = [ [0, 2, 0, 5,

View Solution →