intervals

Intervals

Greedy: Sort by ending points - Max num of non-overlapping intervals inside a range

452.Minimum-Number-of-Arrows-to-Burst-Balloonsarrow-up-right (H-)

435.Non-overlapping-Intervalsarrow-up-right (M+) (aka. 646.Maximum-Length-of-Pair-Chainarrow-up-right)

757.Set-Intersection-Size-At-Least-Two

757.Set-Intersection-Size-At-Least-Twoarrow-up-right (H)

1751.Maximum-Number-of-Events-That-Can-Be-Attended-IIarrow-up-right (H)

Greedy: Sort by starting points - Min num of intervals to cover the range

1326.Minimum-Number-of-Taps-to-Open-to-Water-a-Gardenarrow-up-right (M+)

045.Jump-Game-IIarrow-up-right (M)

1024.Video-Stitchingarrow-up-right (M+)

Sort either by start or endpoint

1288.Remove-Covered-Intervalsarrow-up-right (M+)

DP - TODO

Sweepline

  • Split intervals into Pair(int start, boolean isStart), Pair(int end, boolean isEnd)

252.Meeting-Roomsarrow-up-right (M) 253.Meeting-Rooms-IIarrow-up-right (M+) 056.Merge-Intervalsarrow-up-right (M) 057.Insert-Intervalsarrow-up-right (M)

1272.Remove-Intervalarrow-up-right (M+) 252.Meeting-Roomsarrow-up-right (M) 253.Meeting-Rooms-IIarrow-up-right (M+) 056.Merge-Intervalsarrow-up-right (M) 057.Insert-Intervalsarrow-up-right (M) 732.My-Calendar-IIIarrow-up-right (M) 759.Employee-Free-Timearrow-up-right (M+) 798.Smallest-Rotation-with-Highest-Scorearrow-up-right (H) 995.Minimum-Number-of-K-Consecutive-Bit-Flipsarrow-up-right (H-) 1094.Car-Poolingarrow-up-right (E) 1109.Corporate-Flight-Bookingsarrow-up-right (M) 1589.Maximum-Sum-Obtained-of-Any-Permutationarrow-up-right (M) 1674.Minimum-Moves-to-Make-Array-Complementaryarrow-up-right (H) 1871.Jump-Game-VIIarrow-up-right (M+) 1893.Check if All the Integers in a Range Are Covered (E) 850.Rectangle-Area-IIarrow-up-right (H) 1943.Describe-the-Paintingarrow-up-right (H-) 732.My-Calendar-IIIarrow-up-right (M) 759.Employee-Free-Timearrow-up-right (M+) 798.Smallest-Rotation-with-Highest-Scorearrow-up-right (H) 995.Minimum-Number-of-K-Consecutive-Bit-Flipsarrow-up-right (H-) 1094.Car-Poolingarrow-up-right (E) 1109.Corporate-Flight-Bookingsarrow-up-right (M) 1589.Maximum-Sum-Obtained-of-Any-Permutationarrow-up-right (M) 1674.Minimum-Moves-to-Make-Array-Complementaryarrow-up-right (H) 1871.Jump-Game-VIIarrow-up-right (M+) 1893.Check if All the Integers in a Range Are Covered (E) 850.Rectangle-Area-IIarrow-up-right (H) 1943.Describe-the-Paintingarrow-up-right (H-)

Other

436. Find Right Interval - binary search + map - [TODO]

Template: Merge interval

OPTIONS 1: PriorityQueue

  • Here PriorityQueue is also used for sorting purpose but in-house implementation.

  • A more complicated solution when compared with OPTIONS 2

OPTIONS 2: Sort intervals by start and merge

  • Sort intervals using T/S Complexity: O(nlogn)

OPTIONS 3: Sweepline

  • Count interval start as +1, count interval end as -1

DP: 1235.Maximum-Profit-in-Job-Scheduling

1235.Maximum-Profit-in-Job-Schedulingarrow-up-right (H-)

Sort by start, based on whether selecting ith job or not

  • https://leetcode.com/problems/maximum-profit-in-job-scheduling/discuss/733167/Thinking-process-Top-down-DP-Bottom-up-DP

Naive implementation: O(N^2)

Optimize with binary search: O(NlogN) and zip/unzip

Sort by end, based on how many jobs has been completed

  • https://github.com/wisdompeak/LeetCode/tree/master/Greedy/1235.Maximum-Profit-in-Job-Scheduling

  • Similar thought as above

Greedy

  • Interval + DP + Binary search

  • TODO

    • Use named tuples

    • Limitations of lru_cache

    • Sorted() key word

Last updated