Adobe Interview Question for Data Engineers

Country: India
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
of 3 vote

It does not matter. The start time and the end time of intervals are in equal position for this problem.
[1, 5], [2, 10], [6, 9] is currently sorted by start. You may merge them from left to right and get the result [1,10].
If they were sorted by end time instead - [1, 5], [6, 9],[2, 10]. You could merge them from right to left and get the same result [1, 10].

It just depends on if you wanna start the merge from the left or right side of the given inteval list.
A sample code for when intervals sorted by start time

public List<Interval> merge(List<Interval> intervals) {
    if (intervals.size() <= 1)
        return intervals;
    // Sort by ascending starting point 
    intervals.sort((i1, i2) ->, i2.start));
    List<Interval> result = new LinkedList<Interval>();
    int start = intervals.get(0).start;
    int end = intervals.get(0).end;
    for (Interval interval : intervals) {
        if (interval.start <= end) // Overlapping intervals, move the end if needed
            end = Math.max(end, interval.end);
        else {                     // Disjoint intervals, add the previous one and reset bounds
            result.add(new Interval(start, end));
            start = interval.start;
            end = interval.end;
    // Add the last interval
    result.add(new Interval(start, end));
    return result;

Looking for interview experience sharing and coaching?

Visit for private lessons by FB, Google and Uber engineers

Our ONE TO ONE class offers

SYSTEM DESIGN Courses (highly recommended for candidates for FLAG & U)
ALGORITHMS (conquer DP, Greedy, Graph, Advanced Algos & Clean Coding),
latest interview questions sorted by companies,
mock interviews.

Our students got hired from G, U, FB, Amazon, LinkedIn and other top tier companies after weeks of training.

Feel free to email us with any questions. Thanks!

- aonecoding July 31, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 1 vote

depends what you mean exactly by "merge", e.g.
a: [1..7]
b: [5..10]
c: [9..13]
and you want [1..13] as a merged interval of a,b,c
you might want to sort by start times if you want to merge starting by start. You walk through the sorted intervals, pick the first and if the next overlaps you max on the end until no further overlap with maxed end occurs...

If you like thinking backwards, just do the same from the end with minimized start. Its symetric... so it seems to not matter on the result and run time.

If you want to work a bit more with your intervals, it may make sense to put them into an interval tree. you may google it.

- Chris July 29, 2017 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More