Тёмный

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

AlgorithmHQ
Подписаться 3,5 тыс.
Просмотров 832
50% 1

"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/p...
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...

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 22   
@POOJASINGH-bk8hg
@POOJASINGH-bk8hg 2 месяца назад
Very nice and easy explanation, Thankyou.
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
Glad you liked it !
@MeetPatel-yw2ti
@MeetPatel-yw2ti 2 месяца назад
toh chaliye suru karte hee krishan ka name lekar,...Jay Shree Krishan🙏
@pranjalmishra2602
@pranjalmishra2602 Месяц назад
Good one!
@algorithmsbyaditi
@algorithmsbyaditi Месяц назад
Thanks!
@Rajeevkumar-lm3qb
@Rajeevkumar-lm3qb 2 месяца назад
Keep it up ❤
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
Thank you !
@SahilRaj-yp2zu
@SahilRaj-yp2zu 2 месяца назад
Nice Explanation mam
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
Glad you liked it
@manishkaushik6526
@manishkaushik6526 2 месяца назад
nice solution , actually i solve it in n logn time complexityy , Thanks
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
Glad it helped !
@naveennaik3705
@naveennaik3705 2 месяца назад
O(n) mein toh socha bhi nahi tha😶🔥
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
Thank youu !
@MeetPatel-yw2ti
@MeetPatel-yw2ti 2 месяца назад
good explanation,...keep doing💪
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
Thank you, I will
@mi_7_ra
@mi_7_ra 2 месяца назад
Congratulations for 2k subscribers 🎉
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
Thank you so much 😀
@abhishekanand8574
@abhishekanand8574 2 месяца назад
your algo is so good but how did you think of this solution ?
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
As I mentioned in the video, I saw a solution on leetcode itself
@vinny4161
@vinny4161 2 месяца назад
arey english mey explain karo pls mujhe hindi nahi atha hai
@amanpandey2281
@amanpandey2281 2 месяца назад
get an iPad 😁 to explain better
@algorithmsbyaditi
@algorithmsbyaditi 2 месяца назад
Soon😁
Далее
Fake watermelon by Secret Vlog
00:16
Просмотров 9 млн
Fixing Plastic with Staples
00:18
Просмотров 1,4 млн
Men Vs Women Survive The Wilderness For $500,000
31:48
Arenas, strings and Scuffed Templates in C
12:28
Просмотров 85 тыс.