## Invert Tree - Amazon Top Interview Questions

Given a binary tree root, invert it so that its left subtree and right subtree are swapped and the children are recursively inverted. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [2, null, null], [9, [7, null, null], [12, null, null]]] Output [0, [9, [12, null, null], [7, null, null]], [2, null, null]]

## Island Shape Perimeter - Amazon Top Interview Questions

Given a two-dimensional integer matrix of 1s and 0s where 0 represents empty cell and 1 represents a block that forms a shape, return the perimeter of the shape. There is guaranteed to be exactly one shape, and the shape has no holes in it. Constraints 1 ≤ n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, 1, 1], [0, 1, 0] ] Output 8

## Kth Largest Numbers From Stream - Amazon Top Interview Questions

Implement a data structure with the following methods: KthLargestStream(int[] nums, int k) which constructs the instance. int add(int val) which adds val to nums and returns the k (0-indexed) largest value in nums Constraints 1 ≤ n ≤ 100,000 where n is the length of nums 0 ≤ m ≤ 100,000 where m is the number of calls to add k + 1 ≤ n Example 1 Input methods = ["constructor", "add", "add", "add", "add"] arguments = [[[1, 2, 4, 3], 3], [5], [6], [7], [8]]` Output [None,

## Kth Smallest in a Binary Search Tree - Amazon Top Interview Questions

Given a binary search tree root, and k return the kth (0-indexed) smallest value in root. It is guaranteed that the tree has at least k + 1 nodes. Constraints k ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [3, [2, null, null], [9, [7, [4, null, null], [8, null, null]], [12, null, null]]] k = 2 Output 4 Example 2 Input root = [3, [2, null, null], [9, [7, [4, null, null], [8, null, null]], [12, null, null]]] k = 0 Output 2

## Labyrinthian Possibilities - Amazon Top Interview Questions

You are given an N by M matrix of 0s and 1s. Starting from the top left corner, how many ways are there to reach the bottom right corner? Mod the result by 10 ** 9 + 7. You can only move right and down. 0 represents an empty space while 1 represents a wall you cannot walk through. The top left corner and bottom right corner will always be 0. Constraints 1 ≤ n, m ≤ 250 where n and m are the number of rows and columns in matrix. Example 1 Input matrix = [ [0, 0, 1], [0,