intervals
Intervals
Greedy: Sort by ending points - Max num of non-overlapping intervals inside a range
452.Minimum-Number-of-Arrows-to-Burst-Balloons (H-)
435.Non-overlapping-Intervals (M+) (aka. 646.Maximum-Length-of-Pair-Chain)
757.Set-Intersection-Size-At-Least-Two
757.Set-Intersection-Size-At-Least-Two (H)
1751.Maximum-Number-of-Events-That-Can-Be-Attended-II (H)
Greedy: Sort by starting points - Min num of intervals to cover the range
1326.Minimum-Number-of-Taps-to-Open-to-Water-a-Garden (M+)
045.Jump-Game-II (M)
1024.Video-Stitching (M+)
Sort either by start or endpoint
1288.Remove-Covered-Intervals (M+)
DP - TODO
Sweepline
Split intervals into Pair(int start, boolean isStart), Pair(int end, boolean isEnd)
252.Meeting-Rooms (M) 253.Meeting-Rooms-II (M+) 056.Merge-Intervals (M) 057.Insert-Intervals (M)
1272.Remove-Interval (M+) 252.Meeting-Rooms (M) 253.Meeting-Rooms-II (M+) 056.Merge-Intervals (M) 057.Insert-Intervals (M) 732.My-Calendar-III (M) 759.Employee-Free-Time (M+) 798.Smallest-Rotation-with-Highest-Score (H) 995.Minimum-Number-of-K-Consecutive-Bit-Flips (H-) 1094.Car-Pooling (E) 1109.Corporate-Flight-Bookings (M) 1589.Maximum-Sum-Obtained-of-Any-Permutation (M) 1674.Minimum-Moves-to-Make-Array-Complementary (H) 1871.Jump-Game-VII (M+) 1893.Check if All the Integers in a Range Are Covered (E) 850.Rectangle-Area-II (H) 1943.Describe-the-Painting (H-) 732.My-Calendar-III (M) 759.Employee-Free-Time (M+) 798.Smallest-Rotation-with-Highest-Score (H) 995.Minimum-Number-of-K-Consecutive-Bit-Flips (H-) 1094.Car-Pooling (E) 1109.Corporate-Flight-Bookings (M) 1589.Maximum-Sum-Obtained-of-Any-Permutation (M) 1674.Minimum-Moves-to-Make-Array-Complementary (H) 1871.Jump-Game-VII (M+) 1893.Check if All the Integers in a Range Are Covered (E) 850.Rectangle-Area-II (H) 1943.Describe-the-Painting (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-Scheduling (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