Bird
Raised Fist0

Given intervals = [[1,4],[2,4],[3,6]] and queries = [2,5], what is the output of the function call min_interval_binary_search(intervals, queries)?

easy🧾 Code Trace Q12 of Q15
Intervals - Minimum Interval to Include Each Query
Consider the following Python function implementing the binary search approach for the minimum interval problem. Given intervals = [[1,4],[2,4],[3,6]] and queries = [2,5], what is the output of the function call min_interval_binary_search(intervals, queries)?
A[3, 4]
B[3, 4]
C[3, 4]
D[3, 4]
Step-by-Step Solution
Solution:
  1. Step 1: Sort intervals by length

    Intervals sorted by length: [2,4] length=3, [1,4] length=4, [3,6] length=4.
  2. Step 2: Binary search for each query

    Query=2: smallest interval covering 2 is length=3 ([2,4]). Query=5: smallest interval covering 5 is length=4 ([3,6]).
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Output matches expected minimal interval lengths for queries [OK]
Quick Trick: Trace binary search narrowing on interval lengths [OK]
Common Mistakes:
MISTAKES
  • Off-by-one in interval length calculation
  • Incorrect binary search boundaries
  • Confusing start and end indices
Trap Explanation:
PITFALL
  • All options look identical but only one matches the correct trace; off-by-one errors are common.
Interviewer Note:
CONTEXT
  • Tests ability to mentally execute binary search and interval coverage logic.
Master "Minimum Interval to Include Each Query" in Intervals

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Intervals Quizzes