Left Side View of a Tree - Amazon Top Interview Questions
Given a binary tree root, return the leftmost node's value on each level of the tree. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [5, null, null], [2, null, [1, null, null]]] Output [0, 5, 1]
View Solution →Tree From Pre/Inorder Traversals - Amazon Top Interview Questions
Given a list of unique integers preorder and another list of unique integers inorder, representing the pre-order and in-order traversals of a binary tree, reconstruct the tree and return the root. Constraints n ≤ 100,000 where n is the length of preorder and inorder Example 1 Input preorder = [4, 2, 1, 0, 3] inorder = [2, 1, 0, 3, 4] Output [4, [2, null, [1, null, [0, null, [3, null, null]]]], null]
View Solution →The Auditor - Amazon Top Interview Questions
Spreadsheets often use this alphabetical encoding for its columns: "A", "B", "C", ..., "AA", "AB", "AC", ..., "ZZ", "AAA", "AAB", "AAC", .... Given a string s representing an alphabetical column id, return its column number. For example, given "A", return 1. Given "AA", return 27. Example 1 Input s = "AA" Output 27
View Solution →A Flight of Stairs - Amazon Top Interview Questions
There's a staircase with n steps, and you can climb up either 1 or 2 steps at a time. Given an integer n, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters, so each different order of steps counts as a way. Mod the result by 10 ** 9 + 7. Constraints n ≤ 100,000 Example 1 Input n = 4 Output 5 Explanation There are 5 unique ways: 1, 1, 1, 1 2, 1, 1 1, 2, 1 1, 1, 2 2, 2 Example 2
View Solution →Characters in Each Bracket Depth - Amazon Top Interview Questions
You are a given a string s containing "X", "(", and ")". The string has balanced brackets and in between there are some "X"s along with possibly nested brackets recursively. Return the number of "X"s at each depth of brackets in s, from the shallowest depth to the deepest depth. Constraints 2 ≤ n ≤ 100,000 where n is the length of s Example 1 Input s = "(XX(XX(X))X)" Output [3, 2, 1] Explanation There's three "X"s at depth 0. Two "X"s at depth 1. And one "X" at dept
View Solution →