bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 826. Most Profit Assigning Work

826. Most Profit Assigning Work

Leetcode Solutions

Sorting and Two Pointers Approach

  1. Create a list of jobs where each job is a tuple of (difficulty, profit), and sort this list by difficulty.
  2. Sort the workers array to process them in order of their ability.
  3. Initialize a variable best to keep track of the best profit seen so far, and a variable i to iterate through the jobs.
  4. Iterate through each worker: a. While i is less than the length of the jobs list and the worker's ability is greater than or equal to the difficulty of the ith job, update best to be the maximum of best and the profit of the ith job, and increment i. b. Add the value of best to the total profit.
  5. Return the total profit.
UML Thumbnail

Brute Force Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...