Vertical Lines in Binary Tree - Amazon Top Interview Questions
Given a binary tree root, return the number of unique vertical lines that can be drawn such that every node has a line intersecting it. Each left child is angled at 45 degrees to its left, while the right child is angled at 45 degrees to the right. For example, root and root.left.right are on the same vertical line. Constraints 1 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [2, [3, null, null], null], [4, null, [5, null, null]]] Output 5
View Solution →24 - Amazon Top Interview Questions
You are given a list of four integers nums, each between 0 and 9, in a fixed order. By placing the operators +, -, *, and / (where / is integer division) between the numbers, and grouping them with parentheses, determine whether it is possible to get the value 24. Constraints n = 4 where n is the length of nums 0 ≤ nums[i] ≤ 9 Example 1 Input nums = [5, 2, 7, 8] Output True Explanation We can do (5 * 2 - 7) * 8 = 24 Example 2 Input nums = [7, 9, 7, 4] Ou
View Solution →8-Puzzle - Amazon Top Interview Questions
You are given a 3x3 board of unique integers from 0 to 8, representing the state of a puzzle. In this puzzle, you can swap the 0 with one of its 4 neighbours (if it exists), and you are trying to solve it by obtaining the following configuration: [[0, 1, 2], [3, 4, 5], [6, 7, 8]] Return the minimum number of swaps required to solve the puzzle, or return -1 if it's not possible. Constraints n = 3 where n is the number of rows and columns in board 0 ≤ board[r][c] ≤ 8 Example 1
View Solution →Binary Tree Longest Consecutive Path - Amazon Top Interview Questions
Given a binary tree root, return the length of the longest path consisting of consecutive values between any two nodes in the tree. The path can be consecutively increasing or decreasing. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [2, [1, null, null], [3, [4, [5, null, null], null], [0, null, null]]] Output 5 Explanation A longest path is [1, 2, 3, 4, 5]. Example 2 Input root = [7, null, [6, [8, [4, null, null], null]
View Solution →Boxes All the Way Down - Amazon Top Interview Questions
You are given a two-dimensional list of integers boxes. Each list contains two integers [width, height] which represent the width and height of a box. Given that you can put a box in another box if both of its width and height are smaller than the other box, return the maximum number of boxes you can fit into a box. You cannot rotate the boxes. Constraints n ≤ 100,000 where n is the length of boxes Example 1 Input matrix = [ [10, 10], [9, 9], [5, 5], [4, 9]
View Solution →