Virtual Boolean Array - Google Top Interview Questions
Implement a boolean array which implements the following methods: BooleanArray() which initializes an array of size 2 ** 31 with all false values. void setTrue(int i) which sets the value at index i to true. void setFalse(int i) which sets the value at index i to false. void setAllTrue() which sets the value at every index to true. void setAllFalse() which sets the value at every index to false. boolean getValue(int i) which returns the value at index i. Constraints 0
View Solution →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 →