Skip to content

Practice Maximize the Profit as the Salesman

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2830
LeetCode Problem

Maximize the Profit as the Salesman

Problem Statement

You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1. Additionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that ith buyer wants to buy all the houses from starti to endi for goldi amount of gold. As a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers. Return the maximum amount of gold you can earn. Note that different buyers can't buy the same house, and some houses may remain unsold.

Source: Maximize the Profit as the Salesman on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]
Output
3

# Example 2

Input
n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]
Output
10

Constraints

1 <= n <= 10^5
1 <= offers.length <= 10^5
offers[i].length == 3
0 <= starti <= endi <= n - 1
1 <= goldi <= 10^3

Related LeetCode Problems

Practice more problems similar to Maximize the Profit as the Salesman.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.