title-img


Hoppable - Amazon Top Interview Questions

Given an integer list nums where each number represents the maximum number of hops you can make, determine whether you can reach to the last index starting at index 0. Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [1, 0, 0, 0] Output False Example 2 Input nums = [2, 4, 0, 1, 0] Output True Explanation We can jump from index 0 to 1, and then jump to the end. Example 3 Input nums = [1, 1, 0, 1] Output False Explanati

View Solution →

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 →

Array and Queries

Given an array, you are asked to perform a number of queries and divide the array into what are called, beautiful subsequences. The array A has length n. A function f(A) is defined to be a minimal possible , such that it's possible to divide array A into x beautiful subsequences. Note that each element of an array should belong to exactly one subsequence, and subsequence does not necessarily need to be consecutive. A subsequence S with length len is called beautiful if and only if: l

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 →