Minimum Deletions to Make Character Frequencies Unique | 2 Approaches | MICROSOFT | Leetcode - 1647

Sdílet
Vložit
  • čas přidán 10. 09. 2023
  • This is the 17th Video on our Greedy Playlist.
    In this video we will try to solve a very good Greedy Problem - Minimum Deletions to Make Character Frequencies Unique (Leetcode-1647).
    Trust me, this will no longer be a Medium Problem.
    I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
    We will do live coding after explanation and see if we are able to pass all the test cases.
    Problem Name : Minimum Deletions to Make Character Frequencies Unique
    Company Tags : MICROSOFT
    My solutions on Github : github.com/MAZHARMIK/Intervie...
    Leetcode Link : leetcode.com/problems/minimum...
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Subscribe to my channel : / @codestorywithmik
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook

Komentáře • 49

  • @codeandtalk6
    @codeandtalk6 Před 10 měsíci +1

    ❤❤

  • @Vipulghadi
    @Vipulghadi Před 10 měsíci

    nice sir

  • @souravjoshi2293
    @souravjoshi2293 Před 10 měsíci

    kya mast samjhaya sir. hats off

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Před 10 měsíci +1

    good explanation understood

  • @mihirnatani4479
    @mihirnatani4479 Před 10 měsíci +9

    Solved it on my own by 2nd approach . The way I tackle problems has drastically changed in these 2 months since i started watching your videos. Thanks man!!!

  • @ugcwithaddi
    @ugcwithaddi Před 10 měsíci

    You are phenomenal 🔥🔥✨

  • @taneyasoni
    @taneyasoni Před 10 měsíci +1

    12/30

  • @iloveprogramming9122
    @iloveprogramming9122 Před 10 měsíci +2

    Bhaiya aapke unique , interesting code story ke lover 💝

  • @user-vd2jc7lm3h
    @user-vd2jc7lm3h Před 10 měsíci +1

    2nd approach mein maza aa gaya

  • @floatingpoint7629
    @floatingpoint7629 Před 10 měsíci +1

    thanks for the solution i think this can be also solved via priority queue similary to re organize string

  • @tutuimam3381
    @tutuimam3381 Před 10 měsíci +1

    Amazing explanation👍

  • @dhairyachauhan6622
    @dhairyachauhan6622 Před 10 měsíci +1

    nicely explained bhaiya. wish had someone like you for contest questions

  • @mdmozammil6445
    @mdmozammil6445 Před 10 měsíci +2

    your way of teaching is very good. I want you to make videos explaining solutions for LeetCode contests.

  • @Thriftinghai
    @Thriftinghai Před 10 měsíci

    You are the best bro. I will never get tired of saying this

  • @priyanshusingh3316
    @priyanshusingh3316 Před 10 měsíci +4

    mujhe to paheli slide samjhne me time lag gaya, fir samaj aaya launda greedy ho rha hai, anyway love your videos

    • @Area-fd8ht
      @Area-fd8ht Před 10 měsíci

      Agar gaali diya toh teri maa bhen sab chod dunga

  • @sanjaykatta6499
    @sanjaykatta6499 Před 9 měsíci

    Once again excellent explanation but bro, I didn't understand why this problem qualifies as a greedy problem. This looks like a general approach.

  • @MounikaEMB
    @MounikaEMB Před 10 měsíci

    Great explanation thank you 😊🙏

  • @AlishaKhan-ww3io
    @AlishaKhan-ww3io Před 10 měsíci

    Wow. 2nd Approach was lit and you explained it really well

  • @Abhay14
    @Abhay14 Před 10 měsíci +1

    jbb is question ko maine phli baar khud se dry run kiya pen and papper se then maine socha ki
    unordered_mapmap bnaunga iss map pr 2 loop chlaunga map.second equal ho to minus kr dunga but i was wrong

  • @anuppatankar4294
    @anuppatankar4294 Před 10 měsíci +2

    Great Video 🔥Can you make videos on leetcode contest as well

    • @codestorywithMIK
      @codestorywithMIK  Před 10 měsíci +1

      Thanks a lot Anup.
      For contest, I usually dont get time due to my travel plans during weekends. But i will soon plan this too.

  • @wearevacationuncoverers
    @wearevacationuncoverers Před 10 měsíci

    This guy is a GEM 💎

  • @molyoxide8358
    @molyoxide8358 Před 10 měsíci

    Bro 2nd approach ko toh soch bhi nhi skte.
    out of my mind wla tha

  • @NiveditaKar-xj6ew
    @NiveditaKar-xj6ew Před 10 měsíci +2

    1st approch TC=O(N) N is length of string? becoz for first iteration to fill the freq arr we are traversing all characters present in a string.

    • @codestorywithMIK
      @codestorywithMIK  Před 10 měsíci

      Yes. We traverse the entire string of length n

    • @rachitgupta763
      @rachitgupta763 Před 10 měsíci

      ​@@codestorywithMIKbut sir while loop bhi to h to kya vo TC pr effect karega

    • @codestorywithMIK
      @codestorywithMIK  Před 10 měsíci +1

      The first for loop is O(n) because we iterate over all n characters of the string.
      Also the second for loop + while loop , will only run as many times as there are number of characters. So that’s also O(n) ultimately

  • @rohitshah8904
    @rohitshah8904 Před 10 měsíci

    I solved this question using the first approach but couldn't think of the second way

  • @prnvsgr
    @prnvsgr Před 10 měsíci

    Second approch was something which I didn't even realised😅

  • @it.b.61.prashantsingh87
    @it.b.61.prashantsingh87 Před 10 měsíci

    If I decrease the value of 2 to 0 and then insert it into the set, now the next number is also 2. However, since 2, 1, and 0 are already present in the set, if I try to decrease 2 further, it will decrease till -1 so the result value will be wrong in this case cause you said 0 means nothing so we will not push that into the set.

  • @singhji4149
    @singhji4149 Před 10 měsíci

    How 1st approach gives minimum output?

  • @nikhilthakur6601
    @nikhilthakur6601 Před 10 měsíci

    bro can we do it by dp?
    If yes then make a video on it if possible

  • @Rajdweep
    @Rajdweep Před 10 měsíci

    bro ye wala bhi mujhe dp laga, tried to do it by unbounded knapsack using frequency array after sorting it, lekin ek test case pe error de raha idk why

  • @rupesh9284
    @rupesh9284 Před 10 měsíci +1

    class Solution {
    public class Pair{
    char ch;
    int count;
    public Pair(char ch, int count)
    {
    this.ch =ch;
    this.count= count;
    }
    }
    public int minDeletions(String s) {
    PriorityQueue pq = new PriorityQueue((a,b)->{
    return b.count - a.count;
    });
    int [] freq= new int[26];
    for(int i =0;i

  • @anonymity478
    @anonymity478 Před 10 měsíci

    can you explain why the approach 1 is giving us "minimum" operations ??

  • @mewaconite
    @mewaconite Před 10 měsíci +1

    you could also iterate forward.... and solve it... i tried both
    class Solution {
    public:
    int minDeletions(string s) {
    vector fmap(26, 0);
    for (char &c : s) {
    fmap[c - 'a']++;
    }
    sort(fmap.begin(), fmap.end(), greater());
    int minDel = 0;
    for (int i = 0; i < 25; i++) {
    if (fmap[i + 1] > 0) {
    if (fmap[i + 1] >= fmap[i]) {
    int next = fmap[i + 1];
    fmap[i + 1] = max(0, fmap[i] - 1);
    minDel += (next - fmap[i + 1]);
    }
    }
    }
    return minDel;
    }
    };

  • @suryanshsoni3420
    @suryanshsoni3420 Před 10 měsíci +1

    largest Divisible Subset wala bhi kara do please with all approaches

    • @codestorywithMIK
      @codestorywithMIK  Před 10 měsíci

      Please share the leetcode link ❤️

    • @suryanshsoni3420
      @suryanshsoni3420 Před 10 měsíci

      @@codestorywithMIK leetcode 368

    • @molyoxide8358
      @molyoxide8358 Před 10 měsíci

      @@codestorywithMIK Bro Leetcode 61(Rotate List) wala karwa do na pls

  • @sachinmohanty4577
    @sachinmohanty4577 Před 10 měsíci

    Approach 2 is op MIK🫡

  • @saurabhKumar-hj6yp
    @saurabhKumar-hj6yp Před 10 měsíci +2

    ❤❤