Skip to content

Practice Range Module

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#715
LeetCode Problem

Range Module

Problem Statement

RangeModule tracks real numbers using half-open ranges. addRange(left,right) includes every number in that interval; removeRange removes them; queryRange returns true only when the entire requested interval is tracked. The constructor starts empty. Practice approach: Maintain sorted, disjoint intervals. Addition merges overlaps and touching boundaries; removal can shorten or split intervals; a query must fit inside a tracked interval. Do not model only integer points: gaps between integers also matter. Test a removal splitting one interval into two and queries ending exactly at an untracked boundary.

Source: Range Module on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["RangeModule","addRange","removeRange","queryRange","queryRange","queryRange"]
[[],[4,10],[6,8],[4,6],[5,7],[8,10]]
Output
[null,null,null,true,false,true]
Explanation

Removing [6,8) leaves [4,6) and [8,10). A query crossing the removed interval fails.

Constraints

1 <= left < right <= 10^9
At most 10^4 total method calls.

Related LeetCode Problems

Practice more problems similar to Range Module.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.