Showing posts with label Leetcode 56: Merge Intervals. Show all posts
Showing posts with label Leetcode 56: Merge Intervals. Show all posts

Monday, April 2, 2018

Being interviewer: Leetcode 56: Merge intervals

April 2, 2018

Introduction


It is my mock interview's algorithm called Leetcode 56: Merge intervals. I asked the peer to work on the algorithm by mistake, I like to ask him to work on Meeting Room II.

Algorithm analysis


The peer worked very hard and he gave his analysis for the algorithm. Here is the analysis.

One thing I really like to share is that the peer can write the perfect analysis without any issue in his writing.

The reason the peer can pass code screen and get phone screen of Google, I believe that he definitely has very good analytical skills.



Sunday, January 22, 2017

Code Review: Leetcode 56: Merge Intervals (II)

January 22, 2017

Introduction
Julia chose to study 13 questions posted by Gilad, reputation over 700. (the link is here), she came cross the code review: Finding overlapping time intervals. So, she likes to relate to her own practice. She did some work on Leetcode 56: Merge Interval, so she investigated how her practice was. One fact is that she had not made any submission through leetcode online judge on the algorithm. Her practice was too closed and had zero impact, and she decided to make changes this time.  

Workout

Julia's C# practice, code is  here.

Highlights of practice:

1. Julia studied the Java code, and then tried to figure out how to write a C# comparator. She figure out that it is better to use LINQ instead of comparator. She studies the post on stackoverflow.com.

2. Julia tried Leetcode online judge, first test case failed, when the intervals has only one interval. And then, Julia added edge case. line 92 - 93.

3. Julia submitted Leetcode online judge again, failed test case: two intervals, [1,4], [0,4], the merged interval should [0,4], not [1,4]. Forgot to use sortedIntervals, instead of using intervals. How to avoid this kind of writing issue.

Code review on stackexchange.com, link is here.

January 23, 2017

Code review is here; and C# code is here. She got 7 up-votes and 3 answers in less than 24 hours.

A new study

1. Study C# code review completed by Nick Udell, review link is here.

2. Study tag - inteval questions, review link is here.


Sunday, July 10, 2016

Leetcode 56: Merge Intervals

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.