title-img


Dice Throw - Amazon Top Interview Questions

Given integers n, faces, and total, return the number of ways it is possible to throw n dice with faces faces each to get total. Mod the result by 10 ** 9 + 7. Constraints 1 ≤ n, faces, total ≤ 100 Example 1 Input n = 2 faces = 6 total = 7 Output 6 Explanation There are 6 ways to make 7 with 2 6-sided dice: 1 and 6 6 and 1 2 and 5 5 and 2 3 and 4 4 and 3

View Solution →

Back to Front Linked List - Amazon Top Interview Questions

Given a singly linked list node, reorder it such that we take: the last node, and then the first node, and then the second last node, and then the second node, etc. Can you do it in \mathcal{O}(1)O(1) space? Constraints 0 ≤ n ≤ 100,000 where n is the number of nodes in node Example 1 Input node = [0, 1, 2, 3] Output [3, 0, 2, 1]

View Solution →

Binary Tree Width - Amazon Top Interview Questions

Given a binary tree root, return the maximum width of any level in the tree. The width of a level is the number of nodes that can fit between the leftmost node and the rightmost node. Constraints 1 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [1, [3, null, null], null], [2, [4, [5, null, null], [6, null, null]], null]] Output 3 Explanation The maximum width is 3 since between nodes 3 and 4, we can fit total of 3 nodes: [3, null, 4]

View Solution →

Complete Binary Tree - Amazon Top Interview Questions

Given a binary tree root, return whether it's a complete binary tree. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [1, [1, null, null], [0, null, null]], [0, [1, null, null], [0, null, null]]] Output True Example 2 Input root = [0, [1, [1, null, null], [0, null, null]], [0, null, null]] Output True Example 3 Input root = [0, [1, null, [0, null, null]], [0, null, null]] Output False

View Solution →

Delete Sublist to Make Sum Divisible By K - Amazon Top Interview Questions

You are given a list of positive integers nums and a positive integer k. Return the length of the shortest sublist (can be empty sublist ) you can delete such that the resulting list's sum is divisible by k. You cannot delete the entire list. If it's not possible, return -1. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 8, 6, 4, 5] k = 7 Output 2 Explanation We can remove the sublist [6, 4] to get [1, 8, 5] which sums to 14 and

View Solution →