title-img


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 →

Tic Tac Toe - Amazon Top Interview Questions

Implement the tic-tac-toe game with the following methods: TicTacToe(int n) which instantiates an n x n game board. A player wins a game if their pieces either form a horizontal, vertical, or diagonal line of length n. int move(int r, int c, boolean me) which places the next move at row r and column c. me indicates whether it's my move (me = true) or it's your opponent's (me = false) move. If this move makes you win, return 1, if your opponent wins, return -1, and otherwise return 0. Constr

View Solution →

Twin Trees - Amazon Top Interview Questions

Given two binary trees, root0 and root1, return whether their structure and values are equal. Constraints n ≤ 100,000 where n is the number of nodes in root0 m ≤ 100,000 where m is the number of nodes in root1 Example 1 Input root0 = [0, [5, null, null], [9, null, null]] root1 = [0, [5, null, null], [9, null, null]] Output True Explanation These two trees have the same values and same structure. Example 2 Input root0 = [0, [5, null, null], [9, null, null

View Solution →

Univalue Tree Count - Amazon Top Interview Questions

A univalue tree is a tree where all nodes under it have the same value. Given a binary tree root, return the number of univalue subtrees. Constraints 1 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [1, null, null], [0, [1, [1, null, null], [1, null, null]], [0, null, null]]] Output 5 Explanation The unival trees include four leaf nodes (three of them are 1s, the other one is the rightmost 0), and one subtree in the middle (containin

View Solution →