title-img


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 →

Sudoku Validator - Amazon Top Interview Questions

Sudoku is a puzzle where you're given a 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, and numbers shouldn't repeat within a row, column, or box. Given a filled out sudoku board, return whether it's valid. Constraints n = 9 where n is number of rows and columns in matrix Example 1 Input matrix = [ [4, 2, 6, 5, 7, 1, 3, 9, 8], [8, 5, 7, 2, 9, 3,

View Solution →

Sum of Four Numbers Less Than Target - Amazon Top Interview Questions

You are given four lists of integers A, B, C, D and an integer target. Return the number of different unique indices i, j, k, l such that A[i] + B[j] + C[k] + D[l] ≤ target. Constraints a ≤ 1,000 where a is the length of A b ≤ 1,000 where b is the length of B c ≤ 1,000 where c is the length of C d ≤ 1,000 where d is the length of D Example 1 Input A = [2, 3] B = [5, 2] C = [0] D = [1, 2] target = 6 Output 3 Explanation We can pick the following combin

View Solution →