is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
public class MergeIntervals {
- ivyshushu November 02, 2016public class Interval {
int start, end;
Interval(int start, int end) {
this.start = start;
this.end = end;
}
}
public static void main(String[] args) {
MergeIntervals obj = new MergeIntervals();
obj.test();
}
public void test() {
Interval i1 = new Interval(1,3);
Interval i2 = new Interval(8,10);
Interval i3 = new Interval(2,6);
List<Interval> intervals = new ArrayList<>();
intervals.add(i1);
intervals.add(i2);
intervals.add(i3);
List<Interval> merged = merge(intervals);
int longest = getLongestInterval(merged);
System.out.println(longest);
}
public List<Interval> merge(List<Interval> intervals) {
List<Interval> result = new ArrayList<>();
if (intervals == null || intervals.size() == 0)
return result;
Collections.sort(intervals, new Comparator<Interval>() {
@Override
public int compare(Interval o1, Interval o2) {
if (o1.start != o2.start) {
return o1.start - o2.start;
} else {
return o1.end - o2.end;
}
}
});
Interval pre = intervals.get(0);
for (int i=1; i<intervals.size(); i++) {
Interval curr = intervals.get(i);
if (pre.end < curr.start) { // gap
result.add(pre);
pre = curr;
} else {
Interval merged = new Interval(pre.start, curr.end);
pre = merged;
}
}
result.add(pre);
return result;
}
public int getLongestInterval(List<Interval> intervals) {
int longest = 0;
for (int i=0; i< intervals.size(); i++) {
Interval curr = intervals.get(i);
longest = Math.max(longest, curr.end - curr.start);
}
return longest;
}
}