All questions
Advanced · Java · Intervals
Java: merge overlapping intervals
Java coding interview preparation for QA and SDET roles · ~20 min
This is a Pro program. Practice and solutions require ₹99/month. New coding programs are added every month. Basic programs remain free.
Problem statement
Implement static int[][] mergeIntervals(int[][] intervals).
Closed intervals [start,end], start<=end; touching intervals merge; return sorted result without changing input.
Input & output
mergeIntervals(new int[][]{{1,3},{2,6},{8,10}}) → [[1, 6], [8, 10]]Interview discussion
- Explain the time and auxiliary-space complexity of your approach.
- Which boundary cases matter when testing merge overlapping intervals?
Java 8 · Intervals. Implement the required static method in class Solution. The test runner checks returned values, including boundary cases; printing a sample alone does not solve the exercise.
More Java coding questions
- Java: find search insert positionIntermediate · Binary search
- Java: sort map entries by valueIntermediate · Collections
- Java: find first repeated valueIntermediate · Collections
- Java: subtract one list from anotherIntermediate · Collections
