title-img


Repeated Deletion Sequel - Amazon Top Interview Questions

Given a string s and an integer k, repeatedly delete the earliest k consecutive duplicate characters. Constraints k, n ≤ 100,000 where n is the length of s. Example 1 Input s = "baaabbdddd" k = 3 Output "d" Explanation First we delete the "a"s to get "bbbdddd". Then we delete the "b"s to get "dddd". Then we delete three of the four "d"s to get "d"

View Solution →

Rocketship Rescue - Amazon Top Interview Questions

You are given a list of integers weights representing peoples' weights and an integer limit representing the weight limit of one rocket ship. Each rocketship can take at most two people. Return the minimum number of rocket ships it would take to rescue everyone to Mars. Constraints n ≤ 100,000 where n is the length of weights max(weights) ≤ limit Example 1 Input weights = [200, 300, 200] limit = 400 Output 2 Explanation It would take one rocket ship to ta

View Solution →

Rotate by 90 Degrees Counter-Clockwise - Amazon Top Interview Questions

Given a two-dimensional square matrix, rotate in-place it 90 degrees counter-clockwise. Constraints n = m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] Output [ [3, 6, 9], [2, 5, 8], [1, 4, 7] ]

View Solution →

Second Place - Amazon Top Interview Questions

Given a binary tree root, return the depth of the second deepest leaf. Note that if there are multiple deepest leaves, the second deepest leaf is the next highest one. The root has a depth of 0 and you can assume the answer is guaranteed to exist for the trees given. Constraints n ≤ 100,000 where n is the number of nodes in root. Example 1 Input root = [1, [2, null, null], [3, [4, [6, null, null], null], [5, null, [7, null, null]]]] Output 1 Explanation The the seco

View Solution →

Smallest Intersecting Element - Amazon Top Interview Questions

You are given a two-dimensional list of integers matrix where each row is sorted in ascending order. Return the smallest number that exists in every row. If there's no solution, return -1. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 2, 4], [4, 9, 9], [0, 2, 4] ] Output 4

View Solution →