Minimum Cost to Hire K Workers - Leetcode 857 - Python

  Рет қаралды 11,734

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/minimum...
0:00 - Read the problem
0:30 - Intuition
5:33 - Drawing Explanation
13:00 - Coding Solution
leetcode 857
#neetcode #leetcode #python

Пікірлер: 77
@NeetCodeIO
@NeetCodeIO 28 күн бұрын
Sorry I missed so many days lately. I'll be much more consistent going forward. You can count on it!
@metarus208
@metarus208 27 күн бұрын
pls make more coding content going forward
@yang5843
@yang5843 27 күн бұрын
Would a financial incentive motivate you to make videos the day of?
@diaaabusaada910
@diaaabusaada910 27 күн бұрын
We've missed you my friend😉
@gryffindor6409
@gryffindor6409 27 күн бұрын
ok
@ik6071
@ik6071 27 күн бұрын
is it still possible to upload videos on the days you missed?
@asmodeus159
@asmodeus159 27 күн бұрын
Companies asking this question in Interview ❌ Companies implementing this ✅
@tusharsingh3480
@tusharsingh3480 28 күн бұрын
3:20 "if we wanna be full capitalists" - Neetcode
@venkateshnaidu2133
@venkateshnaidu2133 27 күн бұрын
There's no way I can come up with this logic in an interview
@prakhargupta4320
@prakhargupta4320 26 күн бұрын
may be with some help from the interviewer
@visintel
@visintel 24 күн бұрын
Practice heap medium level questions. It helps me to look at solutions when I’m stuck. You’re right, it’s hard to come up with this but it gets easier when you practice and study solutions. You’ll be stuck less and less with practice
@iliadmitriev01
@iliadmitriev01 27 күн бұрын
*capitalists have left the conversation you can get 20 units of work for the half price (50) no, I can get 15 units for the double price (105)
@JamesBond-mq7pd
@JamesBond-mq7pd 27 күн бұрын
Yup. Absurd
@EduardYudinkov
@EduardYudinkov 27 күн бұрын
Thank you for the best explanation ever! After the first 4-5 minutes of the video, I was able to figure out a solution on my own.
@rawatvinod4164
@rawatvinod4164 27 күн бұрын
this one got me confused for days but your explanations always helps me understand every problem better.
@antm9957
@antm9957 27 күн бұрын
Thanks! Don't disappear for so long.
@kareemadesola6522
@kareemadesola6522 25 күн бұрын
Thank you for significantly reducing the time I would have spent on the editorial
@JRK_RIDES
@JRK_RIDES 27 күн бұрын
Thanks man, your videos help a lot.
@lakshmanprabhu6722
@lakshmanprabhu6722 25 күн бұрын
Best explanation!! Thank you
@taqihaider9879
@taqihaider9879 27 күн бұрын
Best explanation !
@JamesBond-mq7pd
@JamesBond-mq7pd 27 күн бұрын
I have tried to solve this task for 2 hours! Unreal problem!
@krateskim4169
@krateskim4169 27 күн бұрын
Awesome explanation
@sirajussalekin9239
@sirajussalekin9239 27 күн бұрын
this has to be the most convoluted explanation of K workers problem I've heard 😅
@rostislav_vat
@rostislav_vat 27 күн бұрын
thank you neetcode
@ChickenWangTFT
@ChickenWangTFT 27 күн бұрын
thank you king
@LimpBizkit195
@LimpBizkit195 27 күн бұрын
I think the time complexity can be simplified as O(nlogn) since n >= k
@barnetthan9391
@barnetthan9391 27 күн бұрын
thanks goat
@krit2038
@krit2038 27 күн бұрын
What about the case when the max value that you pop from the heap is the value that you have just added, in that case would it still be valid to evaluate res using the current rate?
@aadharjain313
@aadharjain313 27 күн бұрын
same doubt??
@siddharth-gandhi
@siddharth-gandhi 27 күн бұрын
my guess is you can prove that total_quality * rate would be less than the res at that time, so doesn't matter. tho i havent proved lol
@pogman1
@pogman1 27 күн бұрын
It's because since we know that the rates are increasing as we loop through, you can guarantee that total_quality * rate will be larger. I.e. the total quality was 10, we add a new guy with a higher rate, if we pop this guy because he has a higher quantity too, we'll basically be doing 10* higher rate which will be >= 10*prev rate
@aadharjain313
@aadharjain313 27 күн бұрын
@@pogman1 but that won't be the minimum cost then ?
@pogman1
@pogman1 26 күн бұрын
@@aadharjain313 it would be since you take the minimum. In the example I gave it would be min(10* prev rate, 10*higher rate) which is guaranteed to be 10*prev rate bc of what I mentioned
@CS_n00b
@CS_n00b 5 күн бұрын
very cool
@Munchen888
@Munchen888 26 күн бұрын
Please help me with this question. I'm going to use sliding window starting from 1 to len(quality) . From heap I'm going to pop when : while heap and len(heap) > k, heapq.heappop(heap). But I don't realize how to check when I am heappush to heap?
@Techgether
@Techgether 27 күн бұрын
Hi navdeep, any good resource recommendations to learn how to determine space and time complexity for my own created solution? and also any website that can explains DSA terminology well?
@mariansalam
@mariansalam 27 күн бұрын
College
@Techgether
@Techgether 26 күн бұрын
@@mariansalam damn
@kwakukusi4094
@kwakukusi4094 27 күн бұрын
thanks, I did not even understand the question
@Sarwaan001
@Sarwaan001 27 күн бұрын
This is very similar to a question that we ask at Disney+
@torvasdh
@torvasdh 27 күн бұрын
This is somehow worse than current industry pay scaling, so expect to see this adopted next year.
@aritrobiswas6439
@aritrobiswas6439 26 күн бұрын
What I learned today is being too good at your job is not necessarily going to get you a job.
@chien-yucode992
@chien-yucode992 28 күн бұрын
🥳🥳🥳
@juanmacias5922
@juanmacias5922 27 күн бұрын
I think what makes this problem hard is the lack of explanation of what is happening in the question, and solutions haha
@ShikaIE
@ShikaIE 27 күн бұрын
Yes the question is ridiculously confusing
@juanmacias5922
@juanmacias5922 27 күн бұрын
@@ShikaIE right! Even if they just alluded to "grading on a curve" lol
@pastori2672
@pastori2672 27 күн бұрын
i got TLE am i a failiure ?
@_sonu_
@_sonu_ 27 күн бұрын
Hi Bro Are you haring ?
@copilotcoder
@copilotcoder 27 күн бұрын
There is a problem, we are calculating total_quality * rate, but one of the individual wage might hit the wage cap and must be discarded?Can you explain sir
@il5083
@il5083 27 күн бұрын
It's sorted, so the previous rates (wage/quality) are lower, therefore their quality * new_rate would be >= minimum wage.
@ravatez
@ravatez 27 күн бұрын
You are late man! I solved it but in different way. Keep posting. Don't break streak 😂
@nikhilanand984
@nikhilanand984 27 күн бұрын
while we are subtracting the maximum quality (since it's a maxheap) when the size of the heap becomes > k (k + 1), suppose our current quality is the maximum quality and we subtracted it from our total quality, but we are still using it's rate (which will be the maximum rate till now since rates are stored in ascending order) to get the minimum total wage by multiplying it with the total quality till now after the subtraction of the current maximum quality. basically we are multiplying the rate of that current quality with the total previous quality we already calculated an answer for. though this won't change our minimum answer till now since we are multiplying it with a greater rate, but still this is wrong. maybe we can also maintain a maximum quality and whenever we are popping the maximum quality, we won't use its rate to find the answer.
@MykolaPavluchynskyi
@MykolaPavluchynskyi 27 күн бұрын
Yes, this bothers me as well. Maybe we should put to the heap not just quality - but pair we are processing. If if the pair we have to remove - is the same we just added - just skip it...
@MykolaPavluchynskyi
@MykolaPavluchynskyi 27 күн бұрын
Probably wiser would be to delete the max element right after processing with size k, that way don't have such situation at all
@MykolaPavluchynskyi
@MykolaPavluchynskyi 27 күн бұрын
Queue qualityQueue = new PriorityQueue((a,b) -> Integer.compare(b.quality, a.quality)); for (Worker worker : workers) { qualityQueue.add(worker); qualitySum += worker.quality; if (qualityQueue.size() == k) { final double biggestRateByNow = worker.ratePerQuality; final double resultCandidate = qualitySum * biggestRateByNow; result = Math.min(result, resultCandidate); Worker biggestQualityWorker = qualityQueue.poll(); qualitySum -= biggestQualityWorker.quality; } }
@orcus_irl
@orcus_irl 27 күн бұрын
how is he using his pen(whatever) to write on browser bro can someone tell me? is there any software that is smooth as he is using right now? I am open for suggestion regarding software
@MrLeyt1125
@MrLeyt1125 26 күн бұрын
No, he drawing with a real pen on real monitor and takes video with his phone. New video = new monitor, please donate for a new vids
@manuelscott9078
@manuelscott9078 25 күн бұрын
paint 3d
@vishaalkumaranandan2894
@vishaalkumaranandan2894 24 күн бұрын
I am still in some kind of confusion with the code
@Benstokes555
@Benstokes555 27 күн бұрын
AHH DIDNT GET IT
@rajsuriyang3427
@rajsuriyang3427 26 күн бұрын
I didn't even understand this question
@supremoluminary
@supremoluminary 27 күн бұрын
Who just deleted my comment?
@supremoluminary
@supremoluminary 27 күн бұрын
Put my deleted comment back up.
@NeetCodeIO
@NeetCodeIO 27 күн бұрын
pretty sure yt auto deletes some, usually because of urls
@supremoluminary
@supremoluminary 27 күн бұрын
@@NeetCodeIO I put it up four times. The fourth time, it seems to have stuck. We are no longer safe, there is a link to GitHub.
@toseefalikhan2297
@toseefalikhan2297 27 күн бұрын
Best explanation!
Find the Maximum Sum of Node Values - Leetcode 3068 - Python
17:50
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 172 М.
Do you have a friend like this? 🤣#shorts
00:12
dednahype
Рет қаралды 57 МЛН
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 34 МЛН
When Steve And His Dog Don'T Give Away To Each Other 😂️
00:21
BigSchool
Рет қаралды 11 МЛН
Python's 5 Worst Features
19:44
Indently
Рет қаралды 83 М.
Choosing a Database for Systems Design: All you need to know in one video
23:58
All 39 Python Keywords Explained
34:08
Indently
Рет қаралды 100 М.
Svelte 5 Runes Demystified (1/4) - Signal Reactivity Basics
28:15
Peter Makes Websites Ltd
Рет қаралды 1,9 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 147 М.
Time Needed to Buy Tickets - Leetcode 2073 - Python
12:45
NeetCodeIO
Рет қаралды 12 М.
How do indexes make databases read faster?
23:25
Arpit Bhayani
Рет қаралды 48 М.
Cherry Pickup II - Leetcode 1463 - Python
24:00
NeetCodeIO
Рет қаралды 14 М.
SUPER() in Python explained! 🔴
13:06
Bro Code
Рет қаралды 1,7 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 75 М.
Do you have a friend like this? 🤣#shorts
00:12
dednahype
Рет қаралды 57 МЛН