Insert Interval

Given a list of none overlapping intervals sorted by starting time. Insert a new interval. Merge if overlaps. Optimal Solution Insert intervals to result list in three segments. First segment directly insert non-overlapping intervals in front. Second segment keep extending new interval with overlapping intervals. Three segment directly insert non-overlapping intervals remaining. This file contains […]

Missing Ranges

Given a list of integers and a range. Find all the missing ranges within the given range. Two Pointers Have two pointers: prev (point to previous number from the array, initialize to lower – 1) and curr. Walk the array with curr, if number not in the given range, continue to next number. If curr […]

Meeting Room

Meeting Room I Given a list of intervals representing meeting times. Determine a person can attend all meetings. Essentially a merge interval problem. A person can attend all meetings as long as there’s no overlap between meetings. We can first sort the intervals on starting time, break even on ending time. The we walk through […]

Longest Consecutive Sequence

Given an array of integers, find the length of the longest consecutive sequence from the array. Merge Interval When dealing with consecutive numbers scattered in an array, consider using this Merge Interval approach. As number appears, they will start join the interval/range of its consecutive neighbors meanwhile updating boundaries with new length.  Core idea of the […]