title-img


Decode Message - Amazon Top Interview Questions

Given the mapping "a" = 1, "b" = 2, ... "z" = 26, and an encoded message message (as a string), count the number of ways it can be decoded. Constraints n ≤ 100,000 where n is the length of message Example 1 Input message = "111" Output 3 Explanation This can be decoded 3 ways: aaa, ak, and ka. Example 2 Input message = "8" Output 1 Explanation This can be only decoded one way, as h. Example 3 Input message = "12" Output 2 Expl

View Solution →

Interval Overlaps - Amazon Top Interview Questions

You are given a list of closed intervals l0 and another list of intervals l1. Individually, each list is non-overlapping and are sorted in ascending order. Return the overlap of the two intervals sorted in ascending order. Constraints n ≤ 100,000 where n is the length of l0 m ≤ 100,000 where m is the length of l1 Example 1 Input l0 = [ [1, 3], [5, 6], [7, 9] ] l1 = [ [1, 4], [5, 7] ] Output [ [1, 3], [5, 6], [7, 7] ] Examp

View Solution →

Next Greater Element of a Linked List - Amazon Top Interview Questions

Given a singly linked list node, replace every node's value with the first greater node's value to its right. If a node doesn't have a next greater node, set its value to 0. Constraints n ≤ 100,000 where n is the number of nodes in node Example 1 Input node = [3, 2, 4, 5] Output [4, 4, 5, 0] Example 2 Input node = [1, 1, 1, 1] Output [0, 0, 0, 0]

View Solution →

Max Sum Partitioning - Amazon Top Interview Questions

You are given a list of integers nums and an integer k. You must partition nums into contiguous groups of size at most k each, and then set each element in nums to the maximum value of its group. Return the maximum possible sum of the resulting list after partitioning. Constraints n ≤ 1,000 where n is the length of nums 1 ≤ k ≤ n Example 1 Input nums = [1, 6, 3, 2, 2, 5, 1] k = 3 Output 35 Explanation We can partition the list into [1, 6, 3] + [2] + [2, 5, 1] to

View Solution →

Binary Search Tree Validation - Amazon Top Interview Questions

Given a binary tree root, return whether it's a binary search tree. A binary tree node is a binary search tree if : All nodes on its left subtree are smaller than node.val All nodes on its right subtree are bigger than node.val All nodes hold the these properties. Constraint n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [3, [2, null, null], [9, [7, [4, null, null], [8, null, null]], [12, null, null]]] Output True Example 2 Input root =

View Solution →