857. Minimum Cost to Hire K Workers | Priority Queue | Heap | Kinda Sliding Window

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ธ.ค. 2024

ความคิดเห็น • 68

  • @ARYANMITTAL
    @ARYANMITTAL  7 หลายเดือนก่อน +16

    Please do like & share with your friends or other coding communities, ifff and only if you like our videos & want us to make more such regular editorials. Your motivation to watch these videos is to get high package jobs & my motivation is your love ❤

    • @anurag_vish
      @anurag_vish 7 หลายเดือนก่อน

      Bhaiya you are amazing teacher...

  • @shivchauhan795
    @shivchauhan795 7 หลายเดือนก่อน +7

    Bechara was personal🤣. Thanku pura question ache se samajh aa gya.

  • @shikharchaturvedi5093
    @shikharchaturvedi5093 7 หลายเดือนก่อน +3

    One of the best explanation of a hard problem i ever saw. Thanks bro. Keep up the Good work!

  • @mrityunjoybarman9098
    @mrityunjoybarman9098 7 หลายเดือนก่อน +5

    Ohhh god when will I be able to solve these problems all by myself. But great explanation

  • @gursimransingh3707
    @gursimransingh3707 7 หลายเดือนก่อน +7

    bhayia slides v share krdea kro... helpfull raheta hai... notes bnane mai

  • @lavanya_m01
    @lavanya_m01 7 หลายเดือนก่อน +2

    The best explanation! was fun to watch how u called the lowest wage person bechara😂

  • @lavanya_m01
    @lavanya_m01 7 หลายเดือนก่อน +4

    one doubt @ 24:07 Since we're using the ratio of the new quantity, that quantity should be part of the quantitySum.. suppose the heap size > k and the new quantity is the greatest say 5 and we need to remove it.. in that case, what if we remove it from the heap & qualitySum and just use it's ratio?

    • @ARYANMITTAL
      @ARYANMITTAL  7 หลายเดือนก่อน +3

      That is an awesome question, firstly hats off to even think in such deep🫡
      .
      But my claim is : if quality is high of curRatio that we will have to ultimately remove from priority queue, then it will never contribute to minAns.
      .
      .
      Conclusion: thus including or excluding this ratio will never even matter for our ans
      .
      .
      Proof: Also proof is purely mathematically but i’ll explain with an example ( making this example generic )
      .
      .
      Step1- as all ratios are sorted thus number these ratios as r1, r2, r3, r4. Now as they are sorted just assign them random but sorted values. r1 = 1, r2 = 2, r3 = 3, r4 = 4 (you can take any ratio values but sorted)
      Step 2 - now we imagine we had to take 2 employees, and also imagine you are at 4th employee i.e. index = 3 (4th employee)
      Step 3 - (Assumption to prove the fact) - Now we are saying the ith employee has higher quality & we already have lesser k qualities in the heap. Okay, lets say ith employee has quality 5, while you already had in the heap quality of 2 & quality of 1 (imagine for index 1 & 2 respectively)
      Step 4 - Now as ratios are sorted in ascending order and index3 employee had a ratio of 4 (r4 = 4) and quality as 5 (just considered higher than 2 & 1), so wage which i'll be giving this 3rd index employee will be 5 * 4 = 20$
      Step 5 - While if we already had a quality of 2 (taking max quality out of 2 & 1), and we also know its ration will for sure be less than 3rd employee (assumed ratio was 2), thus his wage will be 2*2 = 4 (same will follow for second employee too)
      Thus, it proves, that as ratios are sorted in ascending order, this will make sure we take minRatio & multiply by minQualitySum to get minPaidSalary to these k employees.
      I hope this solves the doubt.

    • @abhimanyuambastha2595
      @abhimanyuambastha2595 7 หลายเดือนก่อน

      The simple explanation is that if we removed the person and used his ratio, that means we are using a higher ratio (since sorted) in the current iteration, but using the quality from last iteration. This will never be minimum than the previous ans and won't matter in the end

  • @ushapandey1088
    @ushapandey1088 7 หลายเดือนก่อน

    Honeslty i derive the formula that u derive , but uske baad how to use it i learnt from u👍..this is my learning

  • @iamnoob7593
    @iamnoob7593 5 หลายเดือนก่อน

    Brilliant Aryan.

  • @chinmoydebnath353
    @chinmoydebnath353 7 หลายเดือนก่อน +1

    good luck, coming up with this during interview😮‍💨

  • @floatingpoint7629
    @floatingpoint7629 7 หลายเดือนก่อน

    your explanation was really good

    • @floatingpoint7629
      @floatingpoint7629 7 หลายเดือนก่อน

      it would have been great if you could have dry run a complete example at the end

  • @navinbarnwal4782
    @navinbarnwal4782 7 หลายเดือนก่อน

    Nice explanation ❤

  • @manoharmanu9240
    @manoharmanu9240 7 หลายเดือนก่อน +1

    Great explanation 🙌

  • @akshayawasthi599
    @akshayawasthi599 7 หลายเดือนก่อน

    great work brother.. hats off..

  • @dhineshd94
    @dhineshd94 7 หลายเดือนก่อน

    best explanation for this problem

  • @HIMANSHUYADAV-dt2kb
    @HIMANSHUYADAV-dt2kb 7 หลายเดือนก่อน

    Excellent explanation😃😃

  • @prathamjain8937
    @prathamjain8937 7 หลายเดือนก่อน

    Amazing explaination , Didn't imagine I will completely understand hard problem in 1 go.
    I know I am asking for lot but can you make a giude on how should I follow your intution building playlists becoz questions are arranged in cronological order and some questions are difficult to understand at first

  • @kandariarjun
    @kandariarjun 7 หลายเดือนก่อน

    You explained it very well. Thanks a lot.

  • @iamnoob7593
    @iamnoob7593 5 หลายเดือนก่อน

    Request you to kindly also do LC 759 , 871.

  • @mukulkhanna5071
    @mukulkhanna5071 7 หลายเดือนก่อน

    This dialogue holds for this awsome video "aryan bhai ke age koi bol skta hai ky....."

    • @ARYANMITTAL
      @ARYANMITTAL  7 หลายเดือนก่อน

      📢🫡📈

  • @ShristiSethiya-ch2he
    @ShristiSethiya-ch2he 7 หลายเดือนก่อน

    Great Explanation!!

  • @parthgupta971
    @parthgupta971 7 หลายเดือนก่อน +2

    @ARYANMITTAL what happen if the i th element got removed from priority queue?

    • @ARYANMITTAL
      @ARYANMITTAL  7 หลายเดือนก่อน +4

      That is an awesome question, firstly hats off to even think in such deep🫡
      .
      But my claim is : if quality is high of curRatio that we will have to ultimately remove from priority queue, then it will never contribute to minAns.
      .
      .
      Conclusion: thus including or excluding this ratio will never even matter for our ans
      .
      .
      Proof: Also proof is purely mathematically but i’ll explain with an example ( making this example generic )
      .
      .
      Step1- as all ratios are sorted thus number these ratios as r1, r2, r3, r4. Now as they are sorted just assign them random but sorted values. r1 = 1, r2 = 2, r3 = 3, r4 = 4 (you can take any ratio values but sorted)
      Step 2 - now we imagine we had to take 2 employees, and also imagine you are at 4th employee i.e. index = 3 (4th employee)
      Step 3 - (Assumption to prove the fact) - Now we are saying the ith employee has higher quality & we already have lesser k qualities in the heap. Okay, lets say ith employee has quality 5, while you already had in the heap quality of 2 & quality of 1 (imagine for index 1 & 2 respectively)
      Step 4 - Now as ratios are sorted in ascending order and index3 employee had a ratio of 4 (r4 = 4) and quality as 5 (just considered higher than 2 & 1), so wage which i'll be giving this 3rd index employee will be 5 * 4 = 20$
      Step 5 - While if we already had a quality of 2 (taking max quality out of 2 & 1), and we also know its ration will for sure be less than 3rd employee (assumed ratio was 2), thus his wage will be 2*2 = 4 (same will follow for second employee too)
      Thus, it proves, that as ratios are sorted in ascending order, this will make sure we take minRatio & multiply by minQualitySum to get minPaidSalary to these k employees.
      I hope this solves the doubt.

    • @parthgupta971
      @parthgupta971 7 หลายเดือนก่อน +1

      I am constantly learning new things from your videos thats why I am able to think in depth. Thank you for these awesome videos bro and awesome explanation too :)

  • @prathameshautade2679
    @prathameshautade2679 7 หลายเดือนก่อน

    Great Explanation, Thanks

  • @vishwakarma-gaurav
    @vishwakarma-gaurav 7 หลายเดือนก่อน

    Amazing 🔥🔥

  • @piyushsingh9320
    @piyushsingh9320 7 หลายเดือนก่อน

    Great Explanation !

  • @missunknown0902
    @missunknown0902 7 หลายเดือนก่อน

    Excellent explanation

  • @cenacr007
    @cenacr007 7 หลายเดือนก่อน

    Well Explained

  • @Anushka20037
    @Anushka20037 5 หลายเดือนก่อน +1

    i don't get him after 18:00

  • @MichaBalcerak
    @MichaBalcerak 7 หลายเดือนก่อน

    What should I do when I don't have such an intuition for questions like that ?

  • @IK-xk7ex
    @IK-xk7ex 7 หลายเดือนก่อน

    Thank you for explanation.

  • @ompatel2212
    @ompatel2212 7 หลายเดือนก่อน +1

    you should share the notes

  • @rajrajesh1669
    @rajrajesh1669 7 หลายเดือนก่อน +1

    Can anyone help me with this part?
    I get it that we will find the minimum pay by sorting the ratios and maintaining a priority queue to get the min qualities, but what if that total cost that we found didn't meet the minimum wage expectation of one or more people?

    • @akshatgoel149
      @akshatgoel149 4 หลายเดือนก่อน

      We are taking values which are behind the current index and the array is sorted based so for ith element either we will pick its own ratio or a ratio bigger than its ratio which will eventually give more than its min wage

  • @avinashkumar8147
    @avinashkumar8147 7 หลายเดือนก่อน

    Best explanation

  • @ShivamYadav-vg5fv
    @ShivamYadav-vg5fv 7 หลายเดือนก่อน

    How do you manage to get these questions done during a live contest?

  • @asmitshukla4649
    @asmitshukla4649 7 หลายเดือนก่อน

    bhaiya jhoot ni bolunga, ekdam sir k uppar se gaya ye question................LEETCODE HARD NI BANTE HAIN MUJHSE😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭

  • @letsgazestar
    @letsgazestar 7 หลายเดือนก่อน

    Please share code solution as well

  • @prashantsahu5117
    @prashantsahu5117 7 หลายเดือนก่อน +4

    hello ji just search for that video got it in just NOW

    • @ARYANMITTAL
      @ARYANMITTAL  7 หลายเดือนก่อน +1

      Bilkul ji ❤, thank you ji 🫂

  • @kartikeyasingh5172
    @kartikeyasingh5172 7 หลายเดือนก่อน

    i am not getting one thing , In the code how am i making sure that i do not pick someone such that the ratio*quality of that person is lesser than his minimun wage ??

    • @ARYANMITTAL
      @ARYANMITTAL  7 หลายเดือนก่อน

      Already explained in video bro, when i told, club both the conditions thus we arrived on our final condition

  • @tanyaraj3129
    @tanyaraj3129 7 หลายเดือนก่อน

    just for your reach commenting good guy

  • @siddheshpatil5995
    @siddheshpatil5995 7 หลายเดือนก่อน

    bro where are we checking that the paid amount is more than minimum wage amount?

    • @nooob_coder
      @nooob_coder 7 หลายเดือนก่อน

      same doubt
      plz reply if got the answer

    • @jevinmakwana6811
      @jevinmakwana6811 7 หลายเดือนก่อน +2

      first we have taken the ratio(wage/q => wage per quality) stored in vectorworkers (dbl:ratio, int:quality). then sorted workers means for all i

    • @nooob_coder
      @nooob_coder 7 หลายเดือนก่อน

      @@jevinmakwana6811 got it in dry run thanks

    • @petermj2804
      @petermj2804 7 หลายเดือนก่อน +1

      Since we are sorting by w/q ratio,if we use w/q ratio for a quality values corresponding to higher w/q ratio,we will see that the wage for the person with high w/q ratio will go below his minimum wage value,and so this condition has to be true for every person whose w/q ratio we are looking to check.

    • @chaitanyaamajala2582
      @chaitanyaamajala2582 7 หลายเดือนก่อน

      @@jevinmakwana6811 Yes

  • @jevinmakwana6811
    @jevinmakwana6811 7 หลายเดือนก่อน

    class Solution {
    public:
    double mincostToHireWorkers(vector& quality, vector& wage, int k) {
    vector workers;
    int n = quality.size();
    for(int i=0; i k){
    q_sum -= q.top();
    q.pop();
    }
    if(q.size() == k)
    ans = min(ans, worker.first*q_sum);
    }
    return ans;
    }
    };

  • @nikeshmali8506
    @nikeshmali8506 7 หลายเดือนก่อน

    if anyone don't want to share then just click on share button and copy the link, it will trick the algo.

  • @AnujGupta-xi5ep
    @AnujGupta-xi5ep 7 หลายเดือนก่อน +1

    Space should be :
    O(n + k)

  • @AmanChandna-bv4tt
    @AmanChandna-bv4tt 7 หลายเดือนก่อน +1

    meri selection ho gyi h?

  • @brp3522
    @brp3522 7 หลายเดือนก่อน +2

    10:30 life of a IOS user

  • @aloksachan8572
    @aloksachan8572 7 หลายเดือนก่อน +1

    maqsad 😅

  • @daveloperkrishana7559
    @daveloperkrishana7559 7 หลายเดือนก่อน +1

    quality* (not quantity)😭

    • @ARYANMITTAL
      @ARYANMITTAL  7 หลายเดือนก่อน

      🥲🙈

    • @sangdilbiswal30
      @sangdilbiswal30 7 หลายเดือนก่อน

      I was getting confused if quantity was another thing

  • @YashAgarwal-tf2rl
    @YashAgarwal-tf2rl 7 หลายเดือนก่อน +3

    bhai ise ganda explanation nhi dekha bol zyda rha hai samjha kuch nhi pa rha

  • @praveensingh5729
    @praveensingh5729 7 หลายเดือนก่อน +5

    bHAI just keep the things simple, don't talk too much.
    what is becha..... this.. that....
    don't try to include extra unnecessary things.

  • @Engineering.Wallah
    @Engineering.Wallah 7 หลายเดือนก่อน

    Great explanation

  • @abiraljain7313
    @abiraljain7313 7 หลายเดือนก่อน

    Great explanation 🔥🔥🤩