Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2830 - Maximize the Profit as the Salesman\.

    Medium

    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 <code>offersi = start<sub>i</sub>, end<sub>i</sub>, gold<sub>i</sub></code>, indicating that <code>i<sup>th</sup></code> buyer wants to buy all the houses from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> for <code>gold<sub>i</sub></code> 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.

    Example 1:

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

    Output: 3

    Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.

    We sell houses in the range 0,0 to 1<sup>st</sup> buyer for 1 gold and houses in the range 1,3 to 3<sup>rd</sup> buyer for 2 golds.

    It can be proven that 3 is the maximum amount of gold we can achieve.

    Example 2:

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

    Output: 10

    Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.

    We sell houses in the range 0,2 to 2<sup>nd</sup> buyer for 10 golds.

    It can be proven that 10 is the maximum amount of gold we can achieve.

    Constraints:

    • <code>1 <= n <= 10<sup>5</sup></code>

    • <code>1 <= offers.length <= 10<sup>5</sup></code>

    • offers[i].length == 3

    • <code>0 <= start<sub>i</sub><= end<sub>i</sub><= n - 1</code>

    • <code>1 <= gold<sub>i</sub><= 10<sup>3</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer maximizeTheProfit(Integer n, List<List<Integer>> offers)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait