Bird
Raised Fist0

What does the function return for intervals = [[0,0]]?

medium🧾 Code Trace Q4 of Q15
Intervals - Non-overlapping Intervals (Max Non-Overlap)
What does the function return for intervals = [[0,0]]?
A0
B2
C1
DError or exception
Step-by-Step Solution
Solution:
  1. Step 1: Sort intervals by end time

    Only one interval [0,0], so sorting does not change order.
  2. Step 2: Greedy selection

    Start=0 >= last_end=-inf, select interval, count=1, last_end=0.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Single interval always selected [OK]
Quick Trick: Single interval -> count=1 [OK]
Common Mistakes:
MISTAKES
  • Assuming zero-length intervals are invalid
  • Off-by-one in comparisons
  • Returning zero for single interval
Trap Explanation:
PITFALL
  • Candidates may think zero-length intervals cannot be selected or cause errors.
Interviewer Note:
CONTEXT
  • Tests handling of edge cases with zero-length intervals.
Master "Non-overlapping Intervals (Max Non-Overlap)" 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