title-img


Stock Span - Amazon Top Interview Questions

Implement a data structure simulating a stock ticker which implements the following method: int next(int price) is called once per day and sets the stock price for today to price. It returns the number of consecutive days from today and prior where the price of the stock was less than or equal to price. Constraints 0 ≤ n ≤ 100,000 where n is the number of calls to next Example 1 Input methods = ["constructor", "next", "next", "next", "next", "next"] arguments = [[], [1], [3],

View Solution →

Search Engine - Amazon Top Interview Questions

Implement a data structure with the following methods: add(String word) which adds a lowercase alphabet string word to the search engine exists(String word) which checks if word is in the engine. word may contain "." which means to match any character Constraints k ≤ 1,000 where k is the length of word n ≤ 100,000 where n is the number of calls to add and exists Example 1 Input methods = ["constructor", "add", "add", "exists", "exists", "exists"] arguments = [[], ["dog"], ["

View Solution →

Non-Adjacent Combination Sum - Amazon Top Interview Questions

You are given a list of positive integers nums and an integer k. Return whether there exists a combination of integers in nums such that their sum is k and none of those elements are adjacent in the original list. Constraints n * k ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 2, 2, 3] k = 4 Output True Explanation We can pick [1, 3] since they are non-adjacent and sums to 4 Example 2 Input nums = [1, 3, 1] k = 4 Output False Ex

View Solution →

Lexicographically Smallest Non-Palindromic String - Amazon Top Interview Questions

You are given a lowercase alphabet string s that is a palindrome. Update one character such that s is no longer a palindrome and is lexicographically smallest. Constraints 2 ≤ n ≤ 100,000 where n is the length of s Example 1 Input s = "racecar" Output "aacecar" Explanation We can change the first "r" to "a" to get the

View Solution →

Interleaved Linked List - Amazon Top Interview Questions

Given two linked lists l0 and l1, return the two linked lists interleaved, starting with l0. If there are leftover nodes in a linked list, they should be added to the end. 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 = [7, 8] l1 = [1, 2] Output [7, 1, 8, 2] Example 2 Input l0 = [7, 8] l1 = [1] Output [7, 1, 8]

View Solution →