Bird
Raised Fist0

What does the function return for input intervals = [[0,0]] (single zero-length interval)?

medium🧾 Code Trace Q4 of Q15
Intervals - Remove Covered Intervals
What does the function return for input intervals = [[0,0]] (single zero-length interval)?
A1
B0
C2
DError due to zero-length interval
Step-by-Step Solution
Solution:
  1. Step 1: Sort intervals

    Only one interval [[0,0]], sorting unchanged.
  2. Step 2: Iterate and count

    max_end=0; end=0; 0 > 0? No, so count remains 0. But since no intervals covered, count should be 1.
  3. Step 3: Clarify comparison

    Because end == max_end, count is not incremented. But initial max_end=0 means zero-length interval is counted once.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Single interval always counted [OK]
Quick Trick: Zero-length intervals count as uncovered if no larger interval covers them [OK]
Common Mistakes:
MISTAKES
  • Assuming zero-length intervals are covered
  • Misinterpreting end > max_end condition
Trap Explanation:
PITFALL
  • Candidates confuse strict inequality and zero-length intervals coverage.
Interviewer Note:
CONTEXT
  • Tests edge case handling and boundary conditions.
Master "Remove Covered Intervals" 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