title-img


Ways to Remove Leaves of a Tree - Google Top Interview Questions

You are given a binary tree root. In one operation you can delete one leaf node in the tree. Return the number of different ways there are to delete the whole tree. Constraints 0 ≤ n ≤ 100,000 Example 1 Input Visualize root = [1, [2, null, null], [3, [4, null, null], null]] Output 3 Explanation The three ways to delete are [2, 4, 3, 1] [4, 2, 3, 1] [4, 3, 2, 1] Solved 92 Attempted 127

View Solution →

Weighted Merge Interval - Google Top Interview Questions

You are given a two-dimensional list of integers intervals. Each element contains [start, end, weight], meaning that during the inclusive integer interval [start, end] its weight is weight. Weight is additive so if we have [[1, 5, 6], [2, 7, 3]], then during [2, 5] we have weight of 9. The input intervals may or may not be overlapping. Return the list of intervals that have the highest weight, sorted in ascending order. The returned intervals should be merged, so [[1, 2], [3,

View Solution →

Window Limits - Google Top Interview Questions

You are given a list of integers nums and integers window and limit. Return whether abs(nums[i] - nums[j]) ≤ limit for every i, j such that abs(i - j) < window. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums 1 ≤ window ≤ n 0 ≤ limit < 2 ** 31 Example 1 Input nums = [1, 3, 7, 5] window = 2 limit = 4 Output True Explanation Every number within a window of size 2 has pair differences of at most 4 (from 3 and 7). Example 2 Input nums

View Solution →

Window Queries 👻 - Google Top Interview Questions

You are given two lists of integers nums and queries. You are also given an integer w. Return a new list where for each query q in queries, we answer the question of how many number of different ways are there for a window of length w to cover an element with value q. Constraints n ≤ 100,000 where n is the length of nums m ≤ n where m is the length of queries 0 ≤ nums[i] < n 0 ≤ queries[i] < n Example 1 Input nums = [2, 1, 2, 3, 4] queries = [2, 1] w = 3 Outp

View Solution →

A Maniacal Walk- Google Top Interview Questions

A person is placed on a list of length length, at index 0, and on each step, they can move right one index or left one index (without going out of bounds), or stay on that index. Given that the person can take exactly n steps, how many unique walks can the person take and reach back to index 0? Mod the result by 10 ** 9 + 7. Constraints length ≤ 1,000 n ≤ 500 Example 1 Input length = 5 n = 3 Output 4 Explanation The four actions are: stay at index 0 3 t

View Solution →