Reverse Linked List Groups - Amazon Top Interview Questions
Given a singly linked list node, and an integer k, reverse every k contiguous group of nodes. Constraints n ≤ 100,000 where n is the number of nodes in node Example 1 Input node = [0, 1, 2, 3] k = 2 Output [1, 0, 3, 2] Example 2 Input node = [0, 1, 2, 3] k = 3 Output [2, 1, 0, 3]
View Solution →Merging K Sorted Lists - Amazon Top Interview Questions
Given a list of sorted lists of integers, merge them into one large sorted list. Constraints 0 ≤ n * m ≤ 100,000 where n is number of rows and m is the longest column in lists Example 1 Input lists = [ [], [], [10, 12], [], [3, 3, 13], [3], [10], [0, 7] ] Output [0, 3, 3, 3, 7, 10, 10, 12, 13]
View Solution →Subtree - Amazon Top Interview Questions
You are given two binary trees root, and target. Return whether target is a subtree of root — that is, whether there's a node in root that is identically same in values and structure as root including all of its descendants. Example 1 Input root = [1, [2, null, null], [3, [4, [6, null, null], null], [5, null, [7, null, null]]]] target = [3, [4, [6, null, null], null], [5, null, [7, null, null]]] Output True Example 2 Input root = [1, [2, null, null], [3, [4, [6, null, nu
View Solution →Majority Vote - Amazon Top Interview Questions
You are given a list of integers nums containing n integers, where each number represents a vote to a candidate. Return the id of the candidate that has \gt \lfloor \frac{n}{2}\rfloor>⌊ 2 n ⌋ votes. If there's not a majority vote, return -1. This should be done in \mathcal{O}(1)O(1) space. Constraints n ≤ 100,000 Example 1 Input nums = [5, 5, 1, 1, 2, 2, 2, 2, 2] Output 2 Example 2 Input nums = [3, 3, 4, 4] Output -1 Explanation Neither 3 o
View Solution →Sort a Linked List - Amazon Top Interview Questions
Given a singly linked list of integers node, sort the nodes by their values in ascending order. Constraints n ≤ 100,000 where n is the number of nodes in node Example 1 Input node = [14, 13, 10] Output [10, 13, 14]
View Solution →