title-img


Hash Table - Amazon Top Interview Questions

Implement a hash table with the following methods: HashTable() constructs a new instance of a hash table put(int key, int val) updates the hash table such that key maps to val get(int key) returns the value associated with key. If there is no such key, then return -1. remove(int key) removes both the key and the value associated with it in the hash table. This should be implemented without using built-in hash table. Constraints n ≤ 100,000 where n is the number of calls to put, get

View Solution →

Matrix Search - Amazon Top Interview Questions

Given a two-dimensional integer matrix, where every row and column is sorted in ascending order, find the kth (0-indexed) smallest number. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 3, 30], [2, 3, 31], [5, 5, 32] ] k = 4 Output 5 Example 2 Input matrix = [ [1, 2, 3] ] k = 0 Output 1 Example 3 Input matrix = [ [1], [2], [3] ] k =

View Solution →

Light Bulb Toggling - Amazon Top Interview Questions

You are given an integer n, and there's n switches in a room all in off position and n people who flip switches as follows: Person 1 comes and flips all switches that are multiples of 1, so all of them. Person 2 flips switches that are multiples of 2: 2, 4, 6, ... Person i flips switches that are multiples of i. Return number of switches that will be in on position at the end. Constraints 0 ≤ n < 2 ** 31 Example 1 Input n = 4 Output 2 Explanation Initially the bulbs

View Solution →

Spiral Matrix - Amazon Top Interview Questions

Given a 2-d array matrix, return elements in spiral order starting from matrix[0][0]. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [6, 9, 8], [1, 8, 0], [5, 1, 2], [8, 0, 3], [1, 6, 4], [8, 8, 10] ] Output [6, 9, 8, 0, 2, 3, 4, 10, 8, 8, 1, 8, 5, 1, 8, 1, 0, 6]

View Solution →

Hoppable - Amazon Top Interview Questions

Given an integer list nums where each number represents the maximum number of hops you can make, determine whether you can reach to the last index starting at index 0. Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [1, 0, 0, 0] Output False Example 2 Input nums = [2, 4, 0, 1, 0] Output True Explanation We can jump from index 0 to 1, and then jump to the end. Example 3 Input nums = [1, 1, 0, 1] Output False Explanati

View Solution →