title-img


Number of Islands - Amazon Top Interview Questions

Given a two-dimensional integer matrix of 1s and 0s, return the number of "islands" in the matrix. A 1 represents land and 0 represents water, so an island is a group of 1s that are neighboring whose perimeter is surrounded by water. Note: Neighbors can only be directly horizontal or vertical, not diagonal. Constraints n, m ≤ 100 where n and m are the number of rows and columns in matrix. Example 1 Input matrix = [ [1, 1], [1, 0] ] Output 1 Example 2 Inpu

View Solution →

Lexicographic Combination Iterator - Amazon Top Interview Questions

Implement an iterator where, given a sorted lowercase alphabet string s of unique characters and an integer k: next() polls the next lexicographically smallest subsequence of length k hasnext() which returns whether the next subsequence exists Constraints n ≤ 100,000 where n is the number of calls to next and hasnext Example 1 Input methods = ["constructor", "next", "next", "next", "hasnext"] arguments = [["abc", 2], [], [], [], []]` Output [None, "ab", "ac", "bc", Fa

View Solution →

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 →