darwinrlo / public

0 stars 0 forks source link

To Share #6

Open darwinrlo opened 4 years ago

darwinrlo commented 4 years ago

Problem

Given a collection of intervals, merge all overlapping intervals.

Source: LeetCode

The idea is, in sorted array of intervals, if interval[i] doesn’t overlap with interval[i-1], then interval[i+1] cannot overlap with interval[i-1] because starting time of interval[i+1] must be greater than or equal to interval[i].

Source: Geeks for Geeks

Why does sorting the intervals by first field put overlapping intervals next to each other?

If overlapping intervals were not placed next to other overlapping intervals after sorting by first, then there should be intervals in between two specific overlapping intervals that do not overlap with either overlapping interval or each other. Let's call these overlapping intervals A and C, A being the one that occurs earlier in the sort order, that is, A.start < C.start. And let the intervals between A and C be B[0], ..., B[n].

Since A.end < C.start ー which would mean that A and C do not overlap. So the specific instance of overlapping intervals with intervening non-overlapping intervals we're looking for does not exist. Hence, after sorting by start, overlapping intervals are placed next to each other.

darwinrlo commented 4 years ago

Keep your ideas in a list. For each idea, keep a collection of positive and negative signals. Categorize each reason as strong or moderate -- don't bother to keep track of weak reasons, whether for or against.

As you run across new information or think of new considerations, add them to the list (which is really a tree) and re-rank your ideas. The ranking of your ideas will be very dynamic -- they will go up and down. And hopefully, the ideas themselves will evolve. Workflowy could be a viable UI: It provides the ability to re-order, restructure, and collapse/expand bullet points.

Ultimately, go with your gut. But the gut feeling you should go with is the gut feeling you get when this list is fairly well-developed and the entirety of it is loaded into your working memory.

darwinrlo commented 4 years ago

Considerations

darwinrlo commented 4 years ago

Possibilities