The thought process u explained in the start , I was able to think of it by myself So proud of myself ..........all thanks to your story to code process😇😇
So many videos on this topic, but the only one that even remotely helped me understand it completely was this one. Thank you so much for taking all the examples to explain, running each dry run explaining everything in depth. Youve earned yourself a subscriber. Thank you again!!!
Bhaiya you're the best, I suck even on 800 codeforces problems, I've gave up 2 time learning DSA, now I've started from today onwards again just because of your simple explanation made me believe I too can do it. I'm blessed to find your channel. Thanks a lot bhaiya. Lots of love and support (:
42:14 - There is a mistake You cannot make all 3 guys in the window as 4. 4 + 4+ 4 = 12 NO. As you cannot decrement 13 to 4. Only way is to make every guy as max guy in that Window. So make all as 13. 13*3 = 39 is what new window sum. ALGO CORRECTION: To get the MAX - then we to sort it. Then only target = Nums[r] works. Just a correction. Kindly mention it or pin the comment for others help. Orelse explaination is awesome. Really the first point - making to a element that is already in array. That doubt I had really on my mind. Why not to any random value. Cleared it like a smooth knife cut on a butter bar.
I have added a small dry-run correction caption from 38:35 (might reflect after a while). Click on "cc" to display them on screen. Thanks a lot 🙂 (Just needed to sort the array)
It's very mind troubling question but you made it look so easier. I've just subscribed to your channel and you gave solutions to lc daily questions which make them look like a piece of cake😅
I did this ques earlier by learning from another utube channel but he just presented the formula no intuition but the way you explained right from binary search and then sliding window i must say what u wrote in caption-I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY. u meaned it men!!!! thank u ❤❤
Simplicity at its best. Thanks Buddy. Is there any list of problems (medium to hard) you have made videos on? Would like to watch them. Please do let me know if there are any such lists available where you have created videos on.
Let me know if this helps - docs.google.com/document/u/0/d/1Hqdu5bivW6kHBSr-hGyvO2kYOKkyTtM3qmhmHYH7s7o/mobilebasic I will soon add more to this doc Thank you 🙏♥️
I have added a small dry-run correction caption from 38:35 (might reflect after a while). Click on "cc" to display them on screen. Thanks a lot 🙂 (Just needed to sort the array)
Hi everyone, I have added a small dry-run correction caption from 38:35 (might reflect after a while). Click on "cc" to display them on screen. Thanks a lot 🙂 (Just needed to sort the array)
The solution cleared 57 test cases but gave me tle: class Solution { public: int maxFrequency(vector& nums, int k) { sort(nums.begin(),nums.end()); int result = 0; for(int i = nums.size()-1; i != 0; i--){ int j = i-1; int count = 0; int temp = k; while(j >= 0 and temp != 0){ temp = temp - (nums[i]-nums[j]); if(temp < 0){ break; } count++; j--; } result = max(result,count); } return result + 1; } };
Bhai jab long long aur int type ke variables ko use karke koi operation/expression perform karte hai to us expression ka result long long hota hai ya int. Please help me out. Great explanation with intuition. Learned new concepts from your video
1st approach sochane ke liye kitna time laga? do you solved any same question before ? becoz that binary search formulae (count * target) and operation = windows - currsum ; that doesn’t come directly into mind. so give me some advice !! nice approach first one you did it on first attempt. 💥
Just solved the question then start witching your video. Surprisingly I came up with the 2nd approach. Although it takes 2 long hours for me to build the intuition. But I think your process of your explanation in previous videos helps me a lot. Specially this video: ruclips.net/video/JrG4tbq6efg/видео.html
@@codestorywithMIK aree why apologies, I was just informing in a friendly student teacher way, ye ques hi bohot confusing hai, but koini maine rattan laga liya, mujhe intuition itna achhe se kick nhi kar rhi thi
sir 41:00 dry run of example {1, 8, 13, 4} is not correct becaue the nums is not sorted. 41:52 when right pointer reaches 4, you calculated the number of operations required to change 8, 13 to 4 but 8 and 13 cannot be changed to 4 cause we can only increment the value. Although the code was correct because we already sorted the array before.
Hey, I am getting runtime error for the following testcast : [40,95,44,37,41,52,07,52,87,64,40,14,41,33,12,34,80,07,80,44,10,9] 7925 Could you help please
i didn't get how the target will always be in the array what if the, the array is [2, 2, 2, 2, 2, 4, 5 ,6] and k = 5, in this case target should be 3 but 3 is not present in the array
In the question it is already stated that you can apply at most K operations means ,we can apply operations but less than K times ,in above example if you keep target as 2 and if you will not apply any operations means you are not incrementing any element by one in that case max frequency still will be 5 times as 2 appears 5 time in array,and it can be treated as target element, Now guess in above same example what will be output if input is 2,2,2,2,2,4,5,6 and k=4 ans still will be 5 as 2 appears 5 times and it can be treated as target.
Help! I'm unable to pass all test cases (Java) class Solution { public int maxFrequency(int[] nums, int k) { Arrays.sort(nums); int n = nums.length; int result = 0; int i = 0; int currSum = 0; for (int j = 0; j < n; j++) { long target = nums[j]; currSum += nums[j]; if ((j-i + 1) * target - currSum > k) { currSum -= nums[i]; i++; } result = Math.max(result, (j - i + 1)); } return result; } }
Hi there, Thank you so much for the precious feedback. I would be glad if you can point out at what point you felt non-intuitive for sliding window ? I will definitely try my best to clear that out. Thanks again ❤️❤️🙏🙏😇😇
bhaiya mera ye solution dekhna maine greedy approach apply ki h 11th testcase pr fail ho rha h can you tell me why ? class Solution { public: int maxFrequency(vector& nums, int k) { sort(nums.begin(), nums.end()); int i=0; int j = nums.size()-1; while(i < j){ if(nums[j] - nums[i]
very bad recursive approch , TLE class Solution { public: int memo[10001]; int dp( vector&nums , int k , int ind , int prev ){ if( ind >= nums.size() or k = 0) pick = 1 + dp( nums , k - (nums[prev] - nums[ind]), ind + 1 , prev ); notPick = dp( nums , k , ind + 1 , prev); return max( pick , notPick ); } int maxFrequency(vector& nums, int k) { // greedy doesn't work , atleast for now // lets just tur dp , there might be some subproblems
memset(memo , -1 , sizeof(memo)); sort(nums.begin() , nums.end() , greater()); int ans = INT_MIN; for( int i = 0 ; i < nums.size() ; i++){ ans = max(ans , dp(nums , k , i , i)); } return ans ; } };
College ke computer lab me apka lecture dekh raha hu, ha teacher se permission lia hai maja agaya bhaiya ❤❤❤
Made my day ❤️❤️❤️😄😇🙏
Damn 😅. Our lab teachers won't even let us open RUclips. Else I would have done the same 🥲
@@codestorywithMIK ❤️❤️
@@wearevacationuncoverers 😄
Nicee 😄
Yaar bhaiya kaise itna achhe se soch lete ho aap, Mere liye to kaafi jyada tough hai ye sab. Par itna achha samjhate ho aap majha aa gya
this was indeed a good problem, definately on the medium hard side, i am happy that i learned something new today
The thought process u explained in the start , I was able to think of it by myself
So proud of myself ..........all thanks to your story to code process😇😇
Most welcome 😊
So many videos on this topic, but the only one that even remotely helped me understand it completely was this one. Thank you so much for taking all the examples to explain, running each dry run explaining everything in depth. Youve earned yourself a subscriber. Thank you again!!!
You're so welcome! ❤️🙏
Bhai bohot bohot shukriya ! Bohot pyaar se samjaya!
Bhaiya you're the best, I suck even on 800 codeforces problems, I've gave up 2 time learning DSA, now I've started from today onwards again just because of your simple explanation made me believe I too can do it. I'm blessed to find your channel.
Thanks a lot bhaiya. Lots of love and support (:
42:14 - There is a mistake
You cannot make all 3 guys in the window as 4. 4 + 4+ 4 = 12 NO.
As you cannot decrement 13 to 4.
Only way is to make every guy as max guy in that Window.
So make all as 13.
13*3 = 39 is what new window sum.
ALGO CORRECTION: To get the MAX - then we to sort it. Then only target = Nums[r] works.
Just a correction. Kindly mention it or pin the comment for others help.
Orelse explaination is awesome. Really the first point - making to a element that is already in array. That doubt I had really on my mind. Why not to any random value.
Cleared it like a smooth knife cut on a butter bar.
Yes yes, let me add that in the caption.
Thank you 🙏😇
I have added a small dry-run correction caption from 38:35 (might reflect after a while). Click on "cc" to display them on screen. Thanks a lot 🙂 (Just needed to sort the array)
It's very mind troubling question but you made it look so easier. I've just subscribed to your channel and you gave solutions to lc daily questions which make them look like a piece of cake😅
bhai learned lot of things from this video. thanks.
I did this ques earlier by learning from another utube channel but he just presented the formula no intuition but the way you explained right from binary search and then sliding window i must say what u wrote in caption-I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY. u meaned it men!!!! thank u ❤❤
❤️❤️🙏🙏
keep uploading these type of lecture sir
hatsoff to ur fist apprach bro..
Your doing a lot of hardwork for us ....❤
Thank you so much for watching 🙏🙏🙏
Very Nicely Explained.
Loved the explanation 🤌✨️
I love watching your videos. Doing great bhaiya.
Thank you so much 😀
Simplicity at its best. Thanks Buddy.
Is there any list of problems (medium to hard) you have made videos on? Would like to watch them.
Please do let me know if there are any such lists available where you have created videos on.
Let me know if this helps - docs.google.com/document/u/0/d/1Hqdu5bivW6kHBSr-hGyvO2kYOKkyTtM3qmhmHYH7s7o/mobilebasic
I will soon add more to this doc
Thank you 🙏♥️
@@codestorywithMIK Thank you so much. I will watch your videos and start practicing.
Ur voice is cute Bhaiya 😊
very nice explanation
Great Explanation 🔥
Incredible content
very nice explnation sir
Thank u so much...........learnt a lot 💖💖
Amazing explanation, I like these in-depth videos, teaches me a lot.
Glad it was helpful! 🙏😇
thank u so much
Very nicely explained ❤
👌🏻👌🏻👌🏻That’s pure Art
best of best , keep doing ❤
intuition is good, it would be better if you said array is sorted before applying the sliding window in 1st sliding window example.
Yes, my bad I missed that. I have added a small caption for correction. Thank you 😇🙏
I have added a small dry-run correction caption from 38:35 (might reflect after a while). Click on "cc" to display them on screen. Thanks a lot 🙂 (Just needed to sort the array)
Again THE best 😊
ur consistency is an inspiration💖💖
Means a lot 😇🙏
Hi everyone,
I have added a small dry-run correction caption from 38:35 (might reflect after a while). Click on "cc" to display them on screen. Thanks a lot 🙂 (Just needed to sort the array)
public int maxFrequency (int[]nums,int k){
int ans=0;long sum=0;
Arrays.sort (nums);
for(int i=0,j=0;j
The solution cleared 57 test cases but gave me tle:
class Solution {
public:
int maxFrequency(vector& nums, int k) {
sort(nums.begin(),nums.end());
int result = 0;
for(int i = nums.size()-1; i != 0; i--){
int j = i-1;
int count = 0;
int temp = k;
while(j >= 0 and temp != 0){
temp = temp - (nums[i]-nums[j]);
if(temp < 0){
break;
}
count++;
j--;
}
result = max(result,count);
}
return result + 1;
}
};
Amazing ❤❤❤❤
Thankyou sir
if we have array like [1,1,1,4] and k=3
then we can have 2 as max frequency instead of 4.?????
yes exactly,
can i directly jump to sliding window soln and skipping that binary wala sol becoz that seems to be difficult?
Bhai jab long long aur int type ke variables ko use karke koi operation/expression perform karte hai to us expression ka result long long hota hai ya int. Please help me out. Great explanation with intuition. Learned new concepts from your video
1st approach sochane ke liye kitna time laga? do you solved any same question before ? becoz that binary search formulae (count * target) and operation = windows - currsum ; that doesn’t come directly into mind. so give me some advice !!
nice approach first one you did it on first attempt. 💥
sir, if -1e5
Just solved the question then start witching your video. Surprisingly I came up with the 2nd approach. Although it takes 2 long hours for me to build the intuition. But I think your process of your explanation in previous videos helps me a lot. Specially this video: ruclips.net/video/JrG4tbq6efg/видео.html
Same bro
bhai har video smjh aajati hai almost aapki, iss baar sachmein kuchhh smjh nhi aaaya, sach mein
Apologies if you felt so.
Would you share what part was confusing, i will try my best to explain it here ❤️
@@codestorywithMIK aree why apologies, I was just informing in a friendly student teacher way, ye ques hi bohot confusing hai, but koini maine rattan laga liya, mujhe intuition itna achhe se kick nhi kar rhi thi
Solved it only after seeing the sliding window tag 😢
instead of prefix sum can't we use inbuilt stl function for computing sum ?? Will it be good or not ?
Accumulate?
@@ru45098 yeahh that one only
Actually accumulate will internally take O(n) time. That’s why prefix sum array is considered.
@@codestorywithMIK ohkk , understood
sir 41:00 dry run of example {1, 8, 13, 4} is not correct becaue the nums is not sorted. 41:52 when right pointer reaches 4, you calculated the number of operations required to change 8, 13 to 4 but 8 and 13 cannot be changed to 4 cause we can only increment the value. Although the code was correct because we already sorted the array before.
Yes yes. Small correction there.
But i hope the explanation was clear.
Thanks Pankaj 😇🙏
explanation is great as always ❤️
Hey, I am getting runtime error for the following testcast : [40,95,44,37,41,52,07,52,87,64,40,14,41,33,12,34,80,07,80,44,10,9]
7925
Could you help please
class Solution {
public:
int maxFrequency(vector& nums, int k) {
int n=nums.size();
sort(nums.begin(),nums.end());
vector dif(n-1);
for(int i=0;i
Longest video I have watched
Thank you for watching 🙏😇❤️
What if , we can do both increment or decrement
follow up question aaj ka weekly contest 376 D
Qn-4 ruclips.net/video/Iaz-8ZQYUvs/видео.htmlsi=4qCFdzYompcrUyhy
i didn't get how the target will always be in the array what if the, the array is [2, 2, 2, 2, 2, 4, 5 ,6] and k = 5, in this case target should be 3 but 3 is not present in the array
In the question it is already stated that you can apply at most K operations means ,we can apply operations but less than K times ,in above example if you keep target as 2 and if you will not apply any operations means you are not incrementing any element by one in that case max frequency still will be 5 times as 2 appears 5 time in array,and it can be treated as target element,
Now guess in above same example what will be output if input is 2,2,2,2,2,4,5,6 and k=4 ans still will be 5 as 2 appears 5 times and it can be treated as target.
god level explaination in very sweet voice👌(●'◡'●)
mzaa aa gya
Acha agar exactly k elements hota to kaise tweak krenge?
nvm we just change the condition from
@@xiaoshen194 yes. I think in that case == karke hojaega
can you explain in java sorting ka sc=logn count karta hai?
if you talking about sc then no , your time complexitey will nlogn
bhaiya how can i thank you???
When you get placed, give me a small treat of “kulhad waali chai” 😇
Keep working hard 🙌😇
Help! I'm unable to pass all test cases (Java)
class Solution {
public int maxFrequency(int[] nums, int k) {
Arrays.sort(nums);
int n = nums.length;
int result = 0;
int i = 0;
int currSum = 0;
for (int j = 0; j < n; j++) {
long target = nums[j];
currSum += nums[j];
if ((j-i + 1) * target - currSum > k) {
currSum -= nums[i];
i++;
}
result = Math.max(result, (j - i + 1));
}
return result;
}
}
The binary solution was explained really well. However, the sliding window explanation was non intuitive.
Hi there,
Thank you so much for the precious feedback.
I would be glad if you can point out at what point you felt non-intuitive for sliding window ?
I will definitely try my best to clear that out.
Thanks again ❤️❤️🙏🙏😇😇
bhaiya mera ye solution dekhna maine greedy approach apply ki h 11th testcase pr fail ho rha h can you tell me why ?
class Solution {
public:
int maxFrequency(vector& nums, int k) {
sort(nums.begin(), nums.end());
int i=0; int j = nums.size()-1;
while(i < j){
if(nums[j] - nums[i]
Can you share the test case
@@codestorywithMIK
Nums =
[9930,9923,9983,9997,9934,9952,9945,9914,9985,9982,9970,9932,9985,9902,9975,9990,9922,9990,9994,9937,9996,9964,9943,9963,9911,9925,9935,9945,9933,9916,9930,9938,10000,9916,9911,9959,9957,9907,9913,9916,9993,9930,9975,9924,9988,9923,9910,9925,9977,9981,9927,9930,9927,9925,9923,9904,9928,9928,9986,9903,9985,9954,9938,9911,9952,9974,9926,9920,9972,9983,9973,9917,9995,9973,9977,9947,9936,9975,9954,9932,9964,9972,9935,9946,9966]
K = 3056
very bad recursive approch , TLE
class Solution {
public:
int memo[10001];
int dp( vector&nums , int k , int ind , int prev ){
if( ind >= nums.size() or k = 0)
pick = 1 + dp( nums , k - (nums[prev] - nums[ind]), ind + 1 , prev );
notPick = dp( nums , k , ind + 1 , prev);
return max( pick , notPick );
}
int maxFrequency(vector& nums, int k) {
// greedy doesn't work , atleast for now
// lets just tur dp , there might be some subproblems
memset(memo , -1 , sizeof(memo));
sort(nums.begin() , nums.end() , greater());
int ans = INT_MIN;
for( int i = 0 ; i < nums.size() ; i++){
ans = max(ans , dp(nums , k , i , i));
}
return ans ;
}
};
Always a good thing to try multiple approaches