title-img


Rolling Median - Amazon Top Interview Questions

Implement a RollingMedian class with the following methods: add(int val) which adds val to the data structure median() which retrieves the current median of all numbers added Median of [1, 2, 3] is 2 whereas median of [1, 2, 3, 4] is 2.5. Constraints n ≤ 100,000 where n is the number of calls to add and median Example 1 Input methods = ["constructor", "add", "add", "add", "median", "add", "median"] arguments = [[], [1], [2], [3], [], [4], []]` Output [None, None, Non

View Solution →

Sliding Window Max - Amazon Top Interview Questions

Given a list of integers nums and an integer k, return the maximum values of each sublist of length k. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums. 1 ≤ k ≤ 100,000. Example 1 Input nums = [10, 5, 2, 7, 8, 7] k = 3 Output [10, 7, 8, 8] Explanation 10 = max(10, 5, 2) 7 = max(5, 2, 7) 8 = max(2, 7, 8) 8 = max(7, 8, 7) Example 2 Input nums = [1, 2, 3, 4, 5, 4, 3, 2, 1] k = 3 Output [3, 4, 5, 5, 5, 4, 3] Example 3 Input

View Solution →

Split List to Minimize Largest Sum - Amazon Top Interview Questions

Given a list of non-negative integers nums and an integer k, you can split the list into k non-empty sublists. Return the minimum largest sum of the k sublists. Constraints k ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 3, 2, 4, 9] k = 2 Output 10 Explanation We can split the list into these 2 sublists: [1, 3, 2, 4] and [9].

View Solution →

Stack of Stacks - Amazon Top Interview Questions

Implement a data structure with the following methods: StackOfStacks(int capacity) which instantiates an instance that represents an infinite number of stacks, each with size capacity. void push(int val) which pushes the value val to the leftmost stack that's not full. int pop() which pops the value of the top element of the rightmost non-empty stack. If every stack is empty, return -1. int popStack(int idx) which pops the value of the top element of the idx (0-indexed) stack.

View Solution →

String Expansion - Amazon Top Interview Questions

You are given a string s consisting of lowercase alphabet characters, digits, and brackets"(" and ")". s encodes a longer string and is represented as concatenation of n(t), where n is the number of times t is repeated, and t is either a regular string or it's another encoded string recursively. Return the expanded version of s. Note that t can be the empty string. Example 1 Input s = "2(ye)0(z)2(2(po)w)" Output "yeyepopowpopow"

View Solution →