826. Most Profit Assigning Work | Leetcode Daily Challenge (POTD) 18 June 2024 | Greedy | O(N)

  Рет қаралды 759

AlgorithmHQ

AlgorithmHQ

15 күн бұрын

"826. Most Profit Assigning Work" is a medium-level problem and is featured as the problem of the day for June 18, 2024, on LeetCode. The solution provided in the accompanying video is implemented in Java, but the approach is explained using a dry-run on a whiteboard. This method of explanation makes the video valuable and comprehensible for individuals with different programming backgrounds, as it focuses on the underlying logic rather than language-specific details.
The problem involves assigning tasks to workers such that the total profit is maximized. Each worker has a certain ability, and each task has a specific difficulty and profit. The challenge is to assign each worker the most profitable task they can handle based on their ability.
Intuitive but Inefficient Approach
An intuitive solution might involve using priority queues to manage the tasks and workers, sorting them by difficulty and profit. While this approach can lead to a correct solution, it may not be optimal in terms of time complexity, especially for larger datasets.
Efficient Approach Explained in the Video
The video outlines a more efficient approach that avoids sorting, thereby reducing the overall time complexity. This approach uses an array to store the maximum profit that can be attained at any given difficulty or ability level. Here’s a detailed breakdown:
Initialize Maximum Profit Array: Create an array maxProf where the index represents the difficulty level and the value at that index represents the maximum profit that can be attained for that difficulty.
Populate the Maximum Profit Array: Iterate through the list of tasks, updating the maxProf array with the highest profit available for each difficulty. This ensures that for any given difficulty, you know the best possible profit that can be achieved.
Iterate Over Worker Abilities: For each worker’s ability, update a running maximum profit (currentMaxProfit) which keeps track of the highest profit available up to that ability level.
Calculate Total Profit: Sum up the maximum profits for all workers based on their abilities, using the maxProf array to quickly determine the best possible profit each worker can earn.
To fully grasp the mechanics of this approach, watching the video till the end is highly recommended. The video provides a comprehensive explanation and visual aid through the dry-run, illustrating each step of the algorithm and the rationale behind using the maxProf array. This detailed walkthrough helps solidify the understanding of the algorithm and its implementation.
Link to the problem: leetcode.com/problems/most-pr...
For doubts/queries, please reach out on aditichourasia10@gmail.com
Connect with me on Linkedin: / aditi-chourasia-a2a572121
Other problems for practice:
• 633. Sum of Square Num...
• 502. IPO | Leetcode Da...
• 945. Minimum Increment...
• 2037. Minimum Number o...
• 1122. Relative Sort Ar...
• 648. Replace Words | L...
• 1002. Find Common Char...
• 409. Longest Palindrom...
• 2486. Append Character...

Пікірлер: 20
@MeetPatel-yw2ti
@MeetPatel-yw2ti 13 күн бұрын
toh chaliye suru karte hee krishan ka name lekar,...Jay Shree Krishan🙏
@POOJASINGH-bk8hg
@POOJASINGH-bk8hg 12 күн бұрын
Very nice and easy explanation, Thankyou.
@algorithmsbyaditi
@algorithmsbyaditi 12 күн бұрын
Glad you liked it !
@Rajeevkumar-lm3qb
@Rajeevkumar-lm3qb 13 күн бұрын
Keep it up ❤
@algorithmsbyaditi
@algorithmsbyaditi 12 күн бұрын
Thank you !
@naveennaik3705
@naveennaik3705 13 күн бұрын
O(n) mein toh socha bhi nahi tha😶🔥
@algorithmsbyaditi
@algorithmsbyaditi 13 күн бұрын
Thank youu !
@manishkaushik6526
@manishkaushik6526 13 күн бұрын
nice solution , actually i solve it in n logn time complexityy , Thanks
@algorithmsbyaditi
@algorithmsbyaditi 13 күн бұрын
Glad it helped !
@SahilRaj-yp2zu
@SahilRaj-yp2zu 13 күн бұрын
Nice Explanation mam
@algorithmsbyaditi
@algorithmsbyaditi 13 күн бұрын
Glad you liked it
@MeetPatel-yw2ti
@MeetPatel-yw2ti 13 күн бұрын
good explanation,...keep doing💪
@algorithmsbyaditi
@algorithmsbyaditi 13 күн бұрын
Thank you, I will
@mi_7_ra
@mi_7_ra 13 күн бұрын
Congratulations for 2k subscribers 🎉
@algorithmsbyaditi
@algorithmsbyaditi 13 күн бұрын
Thank you so much 😀
@abhishekanand8574
@abhishekanand8574 13 күн бұрын
your algo is so good but how did you think of this solution ?
@algorithmsbyaditi
@algorithmsbyaditi 13 күн бұрын
As I mentioned in the video, I saw a solution on leetcode itself
@vinny4161
@vinny4161 13 күн бұрын
arey english mey explain karo pls mujhe hindi nahi atha hai
@amanpandey2281
@amanpandey2281 13 күн бұрын
get an iPad 😁 to explain better
@algorithmsbyaditi
@algorithmsbyaditi 13 күн бұрын
Soon😁
Alat Seru Penolong untuk Mimpi Indah Bayi!
00:31
Let's GLOW! Indonesian
Рет қаралды 11 МЛН
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 26 МЛН
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 51 МЛН
Are Coding Bootcamps Worth It? (One Year After Bootcamp)
8:59
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 282 М.
Doing LeetCode Be Like (Coding Interviews Be Like Pt. 2)
4:41
Nicholas T.
Рет қаралды 745 М.
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,3 МЛН
FASTEST Way To Learn Coding and ACTUALLY Get A Job
10:44
Brian Cache
Рет қаралды 961 М.