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 →Number of Islands - Amazon Top Interview Questions
Given a two-dimensional integer matrix of 1s and 0s, return the number of "islands" in the matrix. A 1 represents land and 0 represents water, so an island is a group of 1s that are neighboring whose perimeter is surrounded by water. Note: Neighbors can only be directly horizontal or vertical, not diagonal. Constraints n, m ≤ 100 where n and m are the number of rows and columns in matrix. Example 1 Input matrix = [ [1, 1], [1, 0] ] Output 1 Example 2 Inpu
View Solution →Lexicographic Combination Iterator - Amazon Top Interview Questions
Implement an iterator where, given a sorted lowercase alphabet string s of unique characters and an integer k: next() polls the next lexicographically smallest subsequence of length k hasnext() which returns whether the next subsequence exists Constraints n ≤ 100,000 where n is the number of calls to next and hasnext Example 1 Input methods = ["constructor", "next", "next", "next", "hasnext"] arguments = [["abc", 2], [], [], [], []]` Output [None, "ab", "ac", "bc", Fa
View Solution →