title-img


Postfix Notation Evaluation - Amazon Top Interview Questions

Postfix notation is a way to represent an expression where the operator comes after the operands. For example, ["2", "2", "+", "6", "*"] would be equal to 24, since we have (2 + 2) * 6 = 24. Given a list of strings exp, representing a postfix notation consisting of integers and operators ("+", "-", "*", "/"), evaluate the expression. "/" is integer division. Example 1 Input exp = ["9", "3", "+", "2", "/"] Output 6 Explanation (9 + 3) / 2 = 6 Example 2 Input

View Solution →

Space Battle - Amazon Top Interview Questions

There are a bunch of rockets in space lined up in a row. You are given a list of integers nums representing each rocket's size and direction. If the number is positive it's going right, and if it's negative it's going left. The value of the number represents the rocket's size. If two rockets collide, the smaller one will disappear and the larger one will continue on its course unchanged. If they are the same size and they collide, they'll both explode (both numbers are removed). If two roc

View Solution →

List Partitioning - Amazon Top Interview Questions

Given a list of strings strs, containing the strings "red", "green" and "blue", partition the list so that the red come before green, which come before blue. This should be done in \mathcal{O}(n)O(n) time. Bonus: Can you do it in \mathcal{O}(1)O(1) space? That is, can you do it by only rearranging the list (i.e. without creating any new strings)? Constraints n ≤ 100,000 where n is the length of strs. Example 1 Input strs = ["green", "blue", "red", "red"] Output ["red

View Solution →

Remove Duplicate Numbers - Amazon Top Interview Questions

Given a list of integers nums, remove numbers that appear multiple times in the list, while maintaining order of the appearance in the original list. It should use \mathcal{O}(k)O(k) space where k is the number of unique integers. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 3, 5, 0, 3, 5, 8] Output [1, 0, 8] Explanation Only [1, 0, 8] are unique in the list and that's the order they appear in.

View Solution →

Collecting Coins - Amazon Top Interview Questions

You are given a two-dimensional integer matrix where each cell represents number of coins in that cell. Assuming we start at matrix[0][0], and can only move right or down, find the maximum number of coins you can collect by the bottom right corner. Constraints n, m ≤ 100 where n and m are the number of rows and columns in matrix. Example 1 Input matrix = [ [0, 3, 1, 1], [2, 0, 0, 4] ] Output 9 Explanation We take the following path: [0, 3, 1, 1, 4] Exampl

View Solution →