Range Module
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Track a set of real numbers made up of half-open ranges. A range [left, right) contains every real x with left <= x < right.
Implement:
- RangeModule() starts with nothing tracked.
- addRange(left, right) starts tracking every number in [left, right). Parts already tracked stay tracked.
- queryRange(left, right) returns true if **every** number in [left, right) is currently tracked, otherwise false.
- removeRange(left, right) stops tracking every number in [left, right) that is currently tracked.
Ranges that only touch count as continuous: after adding [1, 5) and [5, 8), queryRange(2, 7) is true. Keep the tracked set as sorted, disjoint intervals so each operation costs O(log n) plus the number of intervals it merges or splits.
Examples
Constraints
- 1 <= left < right <= 10^9
- At most 10^4 calls in total.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.