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 →Break String Into Words - Amazon Top Interview Questions
Given a list of lowercase alphabet strings words and a lowercase alphabet string s, return whether or not the string can be broken down using the list of words. It's not required to use all of the words and you can reuse words. Example 1 Input words = ["quick", "brown", "the", "fox"] s = "thequickbrownfox" Output True Explanation We can break the string down into "the quick brown fox". Example 2 Input words = ["hello", "world"] s = "hellofoobarworld" Output
View Solution →Calculator - Amazon Top Interview Questions
Given a string s representing a mathematical expression with"+", "-", "/", and "*", evaluate and return the result. Note: "/" is integer division. Can you implement without using eval? Example 1 Input s = "1+2*4/6" Output 2 Explanation 1 + ((2 * 4) / 6) = 2
View Solution →Create Largest Number From a List - Amazon Top Interview Questions
Given a list of integers nums, rearrange its order to form the largest possible integer and return it as a string. Constraints n ≤ 1,000 where n is the length of nums nums[i] ≤ 1,000 Example 1 Input nums = [10, 7, 76, 415] Output "77641510" Example 2 Input nums = [961, 745, 331, 794, 923] Output "961923794745331" Example 3 Input nums = [45, 14, 70, 67, 95] Output "9570674514" Example 4 Input nums = [70, 5, 94, 18, 78] Output "9
View Solution →