## 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 →## Tree Shifting - Amazon Top Interview Questions

Given a binary tree root, shift all the nodes as far right as possible while maintaining the relative ordering in each level. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [2, [4, null, null], null], [3, [5, [6, null, null], [7, null, null]], null]] Output [1, [2, null, null], [3, [4, null, null], [5, [6, null, null], [7, null, null]]]] Example 2 Input root = [1, [2, [3, [4, [5, null, null], null], null], null], null] O

View Solution →## Triangle Triplets - Amazon Top Interview Questions

Given a list of non-negative integers nums, return the total number of 3 numbers i < j < k, such that nums[i] + nums[j] > nums[k]. Constraints n ≤ 1,000 where n is the length of nums Example 1 Input nums = [7, 8, 8, 9, 100] Output 4 Explanation We can make these triangles: 7, 8, 8 7, 8, 9 7, 8, 9 (using the other 8) 8, 8, 9

View Solution →## Friend Groups - Amazon Top Interview Questions

You are given an undirected graph friends as an adjacency list, where friends[i] is a list of people i is friends with. Friendships are two-way. Two people are in a friend group as long as there is some path of mutual friends connecting them. Return the total number of friend groups. Constraints n ≤ 250 where n is the length of friends Example 1 Input friends = [ [1], [0, 2], [1], [4], [3], [] ] Output 3 Explanation The three friend gr

View Solution →