title-img


Zero Matrix - Amazon Top Interview Questions

Given a two-dimensional matrix of integers, for each zero in the original matrix, replace all values in its row and column with zero, and return the resulting matrix. Constraints n * m ≤ 100,000 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [5, 0, 0, 5, 8], [9, 8, 10, 3, 9], [0, 7, 2, 3, 1], [8, 0, 6, 7, 2], [4, 1, 8, 5, 10] ] Output [ [0, 0, 0, 0, 0], [0, 0, 0, 3, 9], [0, 0, 0, 0, 0], [0,

View Solution →

Subtree with Maximum Average- Amazon Top Interview Questions

Given a binary tree root, return the maximum average value of a subtree. A subtree is defined to be some node in root including all of its descendants. A subtree average is the sum of the node values divided by the number of nodes. Constraints 1 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [3, null, null], [7, [4, null, null], null]] Output 5.5 Explanation The subtree rooted at 7 has the highest average with (7 + 4) / 2. Example 2

View Solution →

Ancient Astronaut Theory- Amazon Top Interview Questions

You are given a string dictionary, representing a partial lexicographic ordering of ancient astronauts' dictionary. Given a string s, return whether it's a lexicographically sorted string according to this ancient astronaut dictionary. Example 1 Input dictionary = "acb" s = "aaaa h ccc i bbb" Output True Explanation The only constraint is that a comes before c which comes before b . Example 2 Input dictionary = "acb" s = "aaaacccbc" Output False Expla

View Solution →

Rate Limiter - Amazon Top Interview Questions

Implement a rate limiter that limits users’ requests with the following methods: RateLimiter(int expire) constructs a new rate limiter with the given expire time. limit(int uid, int timestamp) represents a request from user uid at time timestamp and should return whether the given user’s request fails. It should fail if the user had a successful request less than expire time ago. You can assume that timestamp is monotonically increasing between requests. Constraints n ≤ 100,000 where

View Solution →

Revolving Door - Amazon Top Interview Questions

You are given a list of list of integers requests. requests[i] contains [time, direction] meaning at time time, a person arrived at the door and either wanted to go in (1) or go out (0). Given that there's only one door and it takes one time unit to use the door, we have the following rules to resolve conflicts: The door starts with in position and then is set to the position used by the last person. If there's only one person at the door at given time, they can use the door. When two or

View Solution →