Hi, I recently gave a Google interview for the Software Engineer role (1 YOE), and I was asked the following question:
Question 1:
You are given an array of length n and q queries. Each query consists of two indices [l, r], representing a subarray from index l to r (both inclusive). For each query, we are allowed to subtract 1 from any subsequence within the range [l, r]. After processing all the queries, determine whether it's possible to make all elements of the array equal to zero.
Example:
arr = [1, 2, 3]
queries = [[0, 1], [1, 2], [0, 2], [1, 2]]
Output: true
Explanation:
query --> arr -- subsequence
[0, 1] --> [0, 1, 3] -- {1, 2}
[1, 2] --> [0, 0, 2] -- {1 , 3}
[0, 2] --> [0, 0, 1] -- {2}
[1, 2] --> [0, 0, 0] -- {1}
Question 2:
You are given a struct Block in C++ that represents the time during which a person is busy, with attributes: personId, startTime, and endTime. You are also given an integer totalTime which represents the total duration. The task is to find the time intervals during which all the persons are free.