title-img


Maximum Non-Adjacent Tree Sum - Amazon Top Interview Questions

Given a binary tree root, return the maximum sum of the integers that can be obtained given no two integers can be adjacent parent to child. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [4, [3, null, null], [2, null, null]], [5, null, null]] Output 10 Explanation We can pick 3, 2 and 5. Note if we picked 4, we wouldn't be able to pick 3 and 2 since they are adjacent.

View Solution →

Perfect Squares - Amazon Top Interview Questions

Write a program that determines the smallest number of square numbers that sum up to n. Constraints 1 ≤ n ≤ 100,000 Example 1 Input n = 4 Output 1 Explanation 4 is already the square of 2. Example 2 Input n = 17 Output 2 Explanation 16 + 1 Example 3 Input n = 18 Output 2 Explanation 9 + 9

View Solution →

Reverse a Linked List - Amazon Top Interview Questions

Given a singly linked list node, return its reverse. Bonus: Can you do this in \mathcal{O}(1)O(1) space? Constraints n ≤ 100,000 where n is the number of nodes in node Example 1 Input node = [1, 2, 3, 4] Output [4, 3, 2, 1] Example 2 Input node = [0, 1] Output [1, 0]

View Solution →

Tree Coloring - Amazon Top Interview Questions

You are given a binary tree root where the value of each node represents its color. In the tree there are at most 2 colors. Return whether it's possible to swap the colors of the nodes any number of times so that no two adjacent nodes have the same color. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [1, null, null], [1, [0, null, [0, null, null]], [0, null, null]]] Output True Explanation We can color the root with 0, the ne

View Solution →

Polyglot Contest - Amazon Top Interview Questions

You are given a two-dimensional list of strings languages, where languages[i] is a list of programming languages person i is fluent in. Consider any list of programming languages such that everyone knows at least one language in it. Return the minimum size of such list. Constraints 1 ≤ n, m ≤ 16 where n and m are the number of rows and columns in languages. 1 ≤ l ≤ 32 where l is the total number of distinct strings in languages. Example 1 Input languages = [ ["Java", "Per

View Solution →