556. Maximum Profit in Job Scheduling (Binary Search + DP)

HardBinary SearchBinary SearchDPSorting

Given jobs each as [startTime, endTime, profit], where no two scheduled jobs may overlap (a job ending at time t does not conflict with one starting at t), return the maximum total profit. Sort by end time and use binary search within a DP. Input: a JSON array of [startTime, endTime, profit].

Input: A JSON array of [startTime, endTime, profit].

Output: Integer — the maximum profit.

Examples

Example 1
Input: [[1,3,50],[3,5,20],[6,19,100],[2,100,200]]
Output: 200
Explanation: The single long job is best.
Example 2
Input: [[1,2,50],[3,4,60],[6,7,70]]
Output: 180
Explanation: All three fit.
Example 3
Input: [[1,2,5]]
Output: 5
Explanation: Single job.

Constraints

Asked by

SwiggyAmazonOracleBloombergMicrosoftInfosys
Solve this problem in the editor →