Merge overlapping and adjacent ranges
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's understanding of interval merging and range manipulation, including handling overlapping and adjacent ranges, edge cases like single-point gaps and extreme values, and the ability to analyze time and space complexity.
Constraints
- Inputs are provided as Python literals matching the function signature.
- Return a deterministic exact-match result.
Examples
Input: ([[1,4],[3,5],[5,7]],)
Expected Output: {'ranges': [[1, 7]], 'totalLength': 6}
Explanation: Prompt example.
Input: ([[10,12],[1,2],[3,4]],)
Expected Output: {'ranges': [[1, 2], [3, 4], [10, 12]], 'totalLength': 4}
Explanation: Single-point gap does not merge.
Input: ([],)
Expected Output: {'ranges': [], 'totalLength': 0}
Explanation: No ranges.
Hints
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.