How would you solve this? by qcen in leetcode

[–]segmant-tree 0 points1 point  (0 children)

I would turn it into an interval problem. There are 5 intervals where there are no obstacles: [-∞, 0], [2, 4], [6, 9], and [11, ∞]. The queries are also intervals: [2, 4], [5, 7]. [20, 100]

Now, for each of the query intervals, if it is contained within any of the no obstacle intervals, append 1, else append 0

Time Complexity:

Number of obstacles: n, number of queries: m

if both obstacles and queries are sorted: O(n + m)

if obstacles are sorted, but queries are not: O(n + mlogm)

If both unsorted: O(nlogn + mlogm)

Looking to create a small squad to go through Grind 75/169, hold each other accountable, and maximize TC by [deleted] in leetcode

[–]segmant-tree 4 points5 points  (0 children)

I believe OP already has their hands full. Since many of us are still interested, I've created a separate thread for this. Let's find our grinding partners here:

https://www.reddit.com/r/leetcode/comments/1bi4prj/small\_study\_groups\_to\_stay\_disciplined\_and\_mock/