## Largest Sum of Non-Adjacent Numbers - Amazon Top Interview Questions

Given a list of integers nums, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [2, 4, 6, 2, 5] Output 13 Explanation We can take 2, 6, and 5 to get 13. Example 2 Input nums = [5, 1, 1, 5] Output 10 Explanation We can take 5 + 5 since they are not adjacent. Example 3 Input nums = [-10, -22, -18, -3, -100] Out

View Solution →## Level Order Traversal - Amazon Top Interview Questions

Given a binary tree root return a level order traversal of the node values. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [0, [5, null, null], [9, [1, [4, null, null], [2, null, null]], [3, null, null]]] Output [0, 5, 9, 1, 3, 4, 2] Example 2 Input root = [0, [1, [2, [3, null, null], null], null], null] Output [0, 1, 2, 3] Example 3 Input root = [0, null, [1, null, [2, null, [3, null, null]]]] Output [0, 1

View Solution →## Linked List Intersection - Amazon Top Interview Questions

Given two sorted linked lists l0, and l1, return a new sorted linked list containing the intersection of the two lists. Constraints n ≤ 100,000 where n is the number of nodes in l0 m ≤ 100,000 where m is the number of nodes in l1 Example 1 Input l0 = [1, 3, 7] l1 = [2, 3, 7, 9] Output [3, 7] Example 2 Input l0 = [1, 2, 3] l1 = [4, 5, 6] Output None

View Solution →## Lone Integer - Amazon Top Interview Questions

You are given a list of integers nums where each integer occurs exactly three times except for one which occurs once. Return the lone integer. Bonus: solve it in \mathcal{O}(1)O(1) space. Constraints n ≤ 100,000 where n is length of nums Example 1 Input nums = [2, 2, 2, 9, 5, 5, 5] Output 9 Example 2 Input nums = [7, 1, 1, 1] Output 7

View Solution →## Long Distance - Amazon Top Interview Questions

Given a list of integers nums, return a new list where each element in the new list is the number of smaller elements to the right of that element in the original input list. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input lst = [3, 4, 9, 6, 1] Output [1, 1, 2, 1, 0] Explanation There is 1 smaller element to the right of 3 There is 1 smaller element to the right of 4 There are 2 smaller elements to the right of 9 There is 1 smaller elemen

View Solution →