July 10, 2016
Leetcode 56: Merge Intervals
study the code:
http://xiaoyaoworm.com/blog/2016/06/27/%E6%96%B0leetcode56-merge-intervals/
https://gist.github.com/jianminchen/a75a3ff78dbb863774b3b97da0d150f8
Write down C# code - 20 minutes workout later.
Sept. 24, 2016
The idea is the following:
1. Sort the list of intervals by start value;
2. Do iteration in the following
base = first.interval
foreach(interval in list)
{
if base.end < interval.start
{
result.add(base);
base = current;
base
___________
current
_____________
}
else
{
(1) base
------------------------
current
---------------------
(2) base
____________________
current
_________
_____________________
new base
}
}
Have some drawing to analyze the problem.
blog reading:
http://www.canadianbusiness.com/leadership/office-space/microsoft-canada-vancouver/
http://www.canadianbusiness.com/leadership/office-space/jordan-banks-facebook-canada/image/2/
Editorial Notes:
1. Julia, could you write down your experience about this problem solving?
Answer: Julia spent 8+ hours to work on the HackerRank world code sprint #7 problem solving.
The idea is to find most simple task you can complete:
Two intervals are not overlapped, so left one should be added to result collections, and move to next one. In order to find the first one, sort the intervals using start time.
No comments:
Post a Comment