Ugly Number Sequel - Amazon Top Interview Questions
Consider a sequence of sorted integers whose prime factors only include 2, 3 or 5. The first few terms are 1, 2, 3, 4, 5, 6, 8, 9, 10. Given an integer n, return the nth (0-index) term of the sequence. Constraints 0 ≤ n ≤ 100,000 Example 1 Input n = 5 Output 6 Explanation Since the first six terms are 1, 2, 3, 4, 5, 6.
View Solution →Add Binary Numbers - Amazon Top Interview Questions
Given two strings a and b that represent binary numbers, add them and return their sum, also as a string. The input strings are guaranteed to be non-empty and contain only 1s and 0s. Constraints n ≤ 100,000 where n is the length of a m ≤ 100,000 where m is the length of b Example 1 Input a = "1" b = "1" Output "10" Example 2 Input a = "111" b = "1" Output "1000"
View Solution →Integer to Roman Numeral - Amazon Top Interview Questions
Given an integer n, return its corresponding Roman numeral. Roman numerals contain the symbols representing values in the following list: "I" = 1 "V" = 5 "X" = 10 "L" = 50 "C" = 100 "D" = 500 "M" = 1000 Symbols are typically written largest to smallest, from left to right, and can be computed by summing the values of all the symbols. However, in some cases, when a symbol of lower value is to the left of a symbol of higher value, then the lower value is subtracted from the higher o
View Solution →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 →