36 · DP Patterns

#1235 Maximum Profit in Job Scheduling

Hardsolve on LeetCode ↗

frequently reported atAirbnbAmazonMicrosoftGoogle

the problem

In plain words

Job i runs from startTime[i] to endTime[i] and pays profit[i]. Choose jobs whose time ranges don't overlap and return the highest total pay. A job may begin at the very moment another one finishes.

in startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]

out 120

Jobs 1–3 (50) and 3–6 (70).

in startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]

out 150

Jobs 1–3, 4–6 and 6–9: 20 + 70 + 60.

in startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]

out 6

  • 1 ≤ n ≤ 5·10⁴
  • 1 ≤ startTime[i] < endTime[i] ≤ 10⁹
  • 1 ≤ profit[i] ≤ 10⁴

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #435
      Non-overlapping Intervals
      Mediumin Intervals
    2. #198
      House Robber
      Mediumin Dynamic Programming
    3. #35
      Search Insert Position
      Easyin Binary Search