title-img


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 →

Run-Length Encoding - Amazon Top Interview Questions

Given a string s, return its run-length encoding. You can assume the string to be encoded have no digits and consists solely of alphabetic characters. Constraints n ≤ 100,000 where n is the length of s Example 1 Input s = "aaaabbbccdaa" Output "4a3b2c1d2a" Example 2 Input s = "abcde" Output "1a1b1c1d1e" Example 3 Input s = "aabba" Output "2a2b1a" Example 4 Input s = "aaaaaaaaaa" Output "10a"

View Solution →

Sum of Two Numbers - Amazon Top Interview Questions

Given a list of numbers nums and a number k, return whether any two elements from the list add up to k. You may not use the same element twice. Note: Numbers can be negative or 0. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [35, 8, 18, 3, 22] k = 11 Output True Explanation 8 + 3 = 11 Example 2 Input nums = [10, 36, 22, 14] k = 4 Output False Explanation No two numbers in this list add up to 4. Example 3

View Solution →