Dynamic Point-in-Range Queries
Updated
Problem statement
Start with an empty collection of integer intervals. Each interval includes both endpoints.
[0,left,right]inserts the interval[left,right].[1,point]asks whetherpointis covered by at least one interval inserted earlier.[2,left,right]asks whether the interval[left,right], including both endpoints, overlaps at least one interval inserted earlier. A single shared endpoint counts as overlap.
Intervals may overlap and endpoints may be negative. Return one Boolean for every point or interval query, in operation order. Only earlier insertions affect a query.
Function
processRangeQueries(operations: int[][]) → boolean[]Examples
Example 1
operations = [[0,1,5],[1,3],[1,6],[0,4,8],[1,6]]return = [true,false,true]Point 3 is covered by [1,5]; point 6 becomes covered only after inserting [4,8].
Example 2
operations = [[1,0],[0,-3,-1],[1,-2],[1,0]]return = [false,true,false]The first query occurs before any insertion. The negative interval covers -2 but not 0.
Example 3
operations = []return = []No queries produce no results.
Example 4
operations = [[2,0,10],[0,3,5],[2,5,8],[2,0,2],[1,4]]return = [false,true,false,true]The first query has no earlier intervals. The second query shares endpoint 5 with [3,5]. The range [0,2] is disjoint, and point 4 is covered.
Constraints
0 <= operations.length <= 200000.- Insert rows and interval-query rows have exactly three integers and satisfy
left <= right. - Point-query rows have exactly two integers.
- Endpoints and query points are signed 32-bit integers.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Streaming Interval Peak ConcurrencyUber · ONSITE INTERVIEWUber interview questions
- Range ModuleWalmart · PHONE SCREENWalmart interview questions
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Group Timestamps into Consecutive-Day IntervalsDuolingo · PHONE SCREENDuolingo interview questions
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Maximum Concurrent Processes (Bar Raiser Round)Amazon · PHONE SCREEN · ONSITE INTERVIEW
- Meeting Scheduling SystemHevo Data · ONSITE INTERVIEW
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Maximum Intervals Overlapping a Fixed-Length WindowBooking.com · ONSITE INTERVIEW