title-img


Inorder Successor - Amazon Top Interview Questions

Given a binary search tree root containing unique values, and an integer t, return the value of the inorder successor of t. That is, return the smallest value greater than t in the tree. Note: you can assume that the inorder successor exists. Bonus: solve it in \mathcal{O}(h)O(h) time and \mathcal{O}(1)O(1) space where h is the height of the tree. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [2, [0, null, [1, null, null]], [3, null, [

View Solution →

Conway's Game of Life - Amazon Top Interview Questions

You are given a two dimensional matrix where a 1 represents a live cell and a 0 represents a dead cell. A cell's (living or dead) neighbors are its immediate horizontal, vertical and diagonal cells. Compute the next state of the matrix using these rules: Any living cell with two or three living neighbors lives. Any dead cell with three living neighbors becomes a live cell. All other cells die. Constraints n, m ≤ 500 where n and m are the number of rows and columns in matrix Example

View Solution →

Cut Palindrome - Amazon Top Interview Questions

Given two strings a and b of equal length, return whether it is possible to cut both strings at a common point such that the first part of a and the second part of b form a palindrome. Constraints n ≤ 100,000 where n is the length of a and b Example 1 Input a = "cat" b = "pac" Output True Explanation If we cut the strings into "c" + "at" and "p" + "ac", then "c" + "ac" is a palindrome. Example 2 Input a = "iceboat" b = "racecar" Output True Explanat

View Solution →

Binary Tree Nodes Around Radius - Amazon Top Interview Questions

You are given a binary tree root containing unique integers and integers target and radius. Return a sorted list of values of all nodes that are distance radius away from the node with value target. Constraints 1 ≤ n ≤ 100,000 where n is number of nodes in root 0 ≤ distance ≤ 100,000 Example 1 Input root = [3, [5, null, null], [2, [1, [6, null, null], [9, null, null]], [4, null, null]]] target = 4 radius = 2 Output [1, 3] Example 2 Input root = [0, null, null] t

View Solution →

Add Linked Lists - Amazon Top Interview Questions

Given a singly linked list l0 and another linked list l1, each representing a number with least significant digits first, return the summed linked list. Note: Each value in the linked list is guaranteed to be between 0 and 9. Constraints n ≤ 100,000 where n is the number of nodes in l0 m ≤ 100,000 where m is the number of nodes in l1 Example 1 Input l0 = [6, 4] l1 = [4, 7] Output [0, 2, 1] Explanation This is 46 + 74 = 120

View Solution →