title-img


Crush Consecutive Numbers - Amazon Top Interview Questions

You are given a list of positive integers nums and a positive integer k. Consider an operation where you merge exactly k consecutive numbers, which costs the sum of those numbers. Given that you can make any number of operations, return the minimum cost necessary to merge all the numbers into one number. If it's not possible, return -1. Constraints n ≤ 40 where n is the length of nums 2 ≤ k ≤ 40 nums[i] ≤ 100 Example 1 Input nums = [1, 2, 4, 3, 2] k = 3 Output

View Solution →

Dictionary Nomad - Amazon Top Interview Questions

You are given a list of strings dictionary and two strings start and end. You want to reach from start to end by modifying one character at a time and making sure each resulting word is also in the dictionary. Words are case-sensitive. Return the minimum number of steps it would take to reach end. Return -1 if it's not possible. Constraints 0 ≤ n * m ≤ 300,000 where n is the length of dictionary and m is the length of the longest string Example 1 Input dictionary = ["day", "say

View Solution →

Divisible Numbers - Amazon Top Interview Questions

You are given integers n, a, b, and c. Return the nth (0-indexed) term of the sorted sequence of integers divisible by a, b or c. Note that by convention the first term of any sequence always starts with 1. Example 1 Input n = 8 a = 2 b = 5 c = 7 Output 12 Explanation The first 9 terms of the sequence are [1, 2, 4, 5, 6, 7, 8, 10, 12]

View Solution →

Farthest Point From Water - Amazon Top Interview Questions

You are given a matrix matrix of 0s and 1s where 0 represents water and 1 represents land. Find the land with the largest Manhattan distance from water and return this distance. If there is no land or no water in the board, return -1. Constraints n, m ≤ 100 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 1, 0], [1, 1, 0], [0, 0, 1] ] Output 2 Explanation grid[0][0] has a Manhattan distance of 2 to water. Exam

View Solution →

Frequency Stack - Amazon Top Interview Questions

Implement a frequency stack with the following methods: FrequencyStack() constructs a new instance of a frequency stack append(int val) appends val to the stack pop() pops and returns the most frequent element in the stack. If there's more than one most frequent element, the one that's closer to the top of the stack should be popped first. You can assume that for pop, the stack is non-empty when they are called. Constraints n ≤ 100,000 where n is the number of methods that will be ca

View Solution →