Minimum Deletions to Make Character Frequencies Unique | 2 Approaches | MICROSOFT | Leetcode - 1647
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
❤❤
nice sir
kya mast samjhaya sir. hats off
good explanation understood
Thank you ❤️🙏
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!!!
So glad to hear that. Thank you so much 🙏😇
You are phenomenal 🔥🔥✨
12/30
Bhaiya aapke unique , interesting code story ke lover 💝
Thank you 😇🙏
2nd approach mein maza aa gaya
thanks for the solution i think this can be also solved via priority queue similary to re organize string
Yes, you are right ❤️
Amazing explanation👍
nicely explained bhaiya. wish had someone like you for contest questions
your way of teaching is very good. I want you to make videos explaining solutions for LeetCode contests.
You are the best bro. I will never get tired of saying this
mujhe to paheli slide samjhne me time lag gaya, fir samaj aaya launda greedy ho rha hai, anyway love your videos
Agar gaali diya toh teri maa bhen sab chod dunga
Once again excellent explanation but bro, I didn't understand why this problem qualifies as a greedy problem. This looks like a general approach.
Great explanation thank you 😊🙏
Wow. 2nd Approach was lit and you explained it really well
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
Great Video 🔥Can you make videos on leetcode contest as well
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.
This guy is a GEM 💎
Bro 2nd approach ko toh soch bhi nhi skte.
out of my mind wla tha
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.
Yes. We traverse the entire string of length n
@@codestorywithMIKbut sir while loop bhi to h to kya vo TC pr effect karega
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
I solved this question using the first approach but couldn't think of the second way
Second approch was something which I didn't even realised😅
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.
How 1st approach gives minimum output?
bro can we do it by dp?
If yes then make a video on it if possible
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
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
can you explain why the approach 1 is giving us "minimum" operations ??
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;
}
};
Thank you so much for sharing ❤️❤️
largest Divisible Subset wala bhi kara do please with all approaches
Please share the leetcode link ❤️
@@codestorywithMIK leetcode 368
@@codestorywithMIK Bro Leetcode 61(Rotate List) wala karwa do na pls
Approach 2 is op MIK🫡
❤❤