L8. Longest Repeating Character Replacement | 2 Pointers and Sliding Window Playlist

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

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

  • @iam_bantu
    @iam_bantu 8 หลายเดือนก่อน +79

    striver bro please upload the greedy playlist asap .. ur lectures are literally dominating all dsa premium courses.. far more better than anyone

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

      it's been already uploaded

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

      bantu bhai ko ram ram

  • @kapilrules
    @kapilrules 3 หลายเดือนก่อน +14

    Thank you brother. I understood it because of you !🙏

  • @kamalakannanng4206
    @kamalakannanng4206 8 หลายเดือนก่อน +42

    Striver - The G.O.A.T of DSA 💥

  • @prasun1595
    @prasun1595 4 หลายเดือนก่อน +13

    dude from 2n to n , kudos to you cuz my mind aint gone beyond that!

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

    I like how you go through the naive solution as well and compare the time and space complexities to the optimized solution

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

    lagta hai jindgi tutorial dekte dekte nikal jayigi

    • @evilgame6197
      @evilgame6197 6 หลายเดือนก่อน +23

      kasam s ...sala karne betho to ye kese krenge...bas yahi chlta h

    • @anandunique1472
      @anandunique1472 5 หลายเดือนก่อน +8

      sahi kaha bhaiya😂koi qn sliding window me slove nahi ho raha he

    • @amitmehta2285
      @amitmehta2285 5 หลายเดือนก่อน +3

      @@anandunique1472 wahi sabse jyda aata hain 🤣

    • @rishujeetrai5780
      @rishujeetrai5780 5 หลายเดือนก่อน +4

      mt dekho tutorial.. khud se code likho fir socho kya glt h. Key Tip: Dry Run your code with pen and paper. At last, kch smjh na aae to tutorial dekho approach smjhne k liye bs.

    • @Bhalu-kl7sq
      @Bhalu-kl7sq 5 หลายเดือนก่อน

      @@rishujeetrai5780 mein to aise kr raha tha pehle video solution dekho then khud try karo

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

    Last 5 minutes are very precious, it is a must watch.
    That trick could be used in other questions as well for optimisation.

    • @rushidesai2836
      @rushidesai2836 3 หลายเดือนก่อน +2

      That he has been mentioning in his previous videos as well.

  • @ayaaniqbal3531
    @ayaaniqbal3531 8 หลายเดือนก่อน +12

    After understanding the logic and without seeing the solution now i am able to code it myself.
    Thanks striver for making us understand this algorithm.😊

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

      Ok let's understand how much you really know the depth. give me pattern of all substring in ABC string with k=1.

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

      @@kaushit {"A", "B", "C", "AB", "BC"} hi hoga na ?

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

    Trick is we dont want to minimize our max freq variable to get better result, ie. if we get result for max freq 3 we will continue to look for max freq greater than 3 if it exists and ignore freq less than equal 3. This will eliminate need of freq map scan and also remove while loop if we want to look for better max length.

    • @SarvanSuthar-d1p
      @SarvanSuthar-d1p 6 หลายเดือนก่อน

      thanks bhaiya,now i got it.

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

      Thanks a lot bro

  • @pailatejeswararao4572
    @pailatejeswararao4572 5 หลายเดือนก่อน +2

    Thankyou very much man.I have watched 6 videos and solved this solution optimally by my own.I will learn everything from you 🙂

  • @rajharsh3739
    @rajharsh3739 8 หลายเดือนก่อน +63

    Bhaiya I am very much Greedy for your Greedy Playlist So when you are uploading that ?? 🙌🙌🤑🤑

    • @tejasjaulkar9658
      @tejasjaulkar9658 8 หลายเดือนก่อน +5

      yes we want greedy playlist bhaiyyaa

    • @dhruvmishra9781
      @dhruvmishra9781 8 หลายเดือนก่อน +4

      same bro plz give greedy playlist after this much needed

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

    Bro when you explain it becomes so easy to understand.. Thank you so much :)

  • @az-zm4ji
    @az-zm4ji 5 หลายเดือนก่อน +3

    First solution witout optimization:
    class Solution {
    public:
    int characterReplacement(string s, int k) {
    //FML
    int l = 0, r = 0, ans = 0, maxf = 0;
    unordered_map umap;
    while(r < s.length()){
    char c = s[r];
    if(umap.find(c) == umap.end()) umap.insert({c, 1});
    else umap.find(c)->second++;
    maxf = max(maxf, umap.find(c)->second);
    while(r - l + 1 - maxf > k){
    umap.find(s[l])->second--;
    for(auto x : umap){
    maxf = max(maxf, x.second);
    }
    l++;
    }
    ans = max(ans, r - l + 1);
    r++;
    }
    return ans;
    }
    };

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

    19:50 - why no need to decrease the maxFreq when frequency of any char in the map decreases

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

    Java Code for java language forks
    class Solution {
    public int characterReplacement(String s, int k) {
    int n=s.length();
    int maxlen=0,maxf=0;
    int i=0,j=0;
    Mapmap=new HashMap();
    while(jk){
    char ch2=s.charAt(i);
    map.put(ch2,map.get(ch2)-1); //decrement the frequency
    i++;
    }
    // if((j-i+1)+maxf

    • @ksnayeem2743
      @ksnayeem2743 วันที่ผ่านมา

      koi python code bhi daaldo

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

    UNDERSTOOD....Thank You So Much for this wonderful video......🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

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

    you are the legend for dsa ......thanks again striver

  • @ShahNawaz-cx3pi
    @ShahNawaz-cx3pi 6 หลายเดือนก่อน +4

    C++ Leetcode solution:
    class Solution {
    public:
    int characterReplacement(string s, int k) {
    int n = s.size();
    int l = 0;
    int r = 0;
    int ans = 0;
    int hash[26]={0};
    int maxFre = 0;
    while(rmaxFre){
    maxFre = hash[s[r]-'A'];
    }
    if((r-l+1)-maxFre>k) {
    hash[s[l]-'A']--;
    l++;
    }
    ans = max(ans, r-l+1);
    r++;
    }
    return ans;
    }
    };

  • @hashcodez757
    @hashcodez757 3 หลายเดือนก่อน

    #UNDERSTOOD

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

    class Solution {
    public int characterReplacement(String s, int k) {
    int maxFreq=0, maxLen=0, l=0, r=0;
    int hash[]=new int[26];
    while(rk){
    hash[s.charAt(l)-'A']--; //Line Number - 9
    l++;
    }
    maxLen=Math.max(maxLen,r-l+1);
    r++;
    }
    return maxLen;
    }
    }
    in the Video he has mentioned at the Line number 9 , hash[s.charAt(r)-'A']--; but above solution worked for me in Java, Anyway Thanks for the Logic Explanation

  • @user-nm2wc1tt9u
    @user-nm2wc1tt9u 6 หลายเดือนก่อน +10

    Optimal:
    class Solution {
    public:
    int characterReplacement(string s, int k) {
    int n = s.size();
    int left = 0, right = 0, maxFreq = 0, maxLen = 0;
    int hash[26] = {0};
    while(right maxFreq){
    maxFreq = hash[s[right]-'A'];
    };
    if((right-left+1)-maxFreq > k){ //trimming the left portion
    hash[s[left]-'A']--;
    left++;
    }
    maxLen = max(maxLen, right-left+1);
    right++;
    }
    return maxLen;
    }
    };

    • @beinginnit
      @beinginnit 5 หลายเดือนก่อน +2

      Though this code runs gets accepted in LC, but i think something is missing: if((right-left+1)-maxFreq > k){ //trimming the left portion
      hash[s[left]-'A']--;
      left++;
      } what if my maxFreq was from i part and also contributing, here i need to recalculate the max freq. I may be wrong but this is what i think.

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

      @@beinginnit Yeah,I see that,but it neetcode channel also he explained in this way to optimize more to O(1) space like this,please have a look at it and explain

  • @psinity
    @psinity 6 หลายเดือนก่อน +2

    19:20 the time complexity should be O( N + N*26) right?

  • @aloklaha8694
    @aloklaha8694 3 หลายเดือนก่อน

    Thanks Striver. I was stuck on what will be the terminating condition for trimming down from left.

  • @amitgundoba9575
    @amitgundoba9575 2 หลายเดือนก่อน +1

    Guys here is an simple code :-----
    class Solution {
    public:
    int characterReplacement(string s, int k) {

    int l=0,r=0,maxlen=0,maxfreq=0;
    int map[26];
    fill(map,map+26,0);
    int n=s.length();
    while(rk){
    map[s[l]-'A']--;
    l++;
    }
    if(r-l+1-maxfreq

  • @sahilshinde3724
    @sahilshinde3724 8 หลายเดือนก่อน +5

    You are writing it in very very small font can u please write which could be visible properly !
    Thanks

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

    Please upload the code.. And looking forward for Heaps playlist please. Nowhere in youtube heaps problems are covered.. Please do it 🙏🏼🙏🏼🙏🏼🙏🏼 . It's being asked in interviews many times

  • @devgarg4331
    @devgarg4331 8 หลายเดือนก่อน +6

    Bhaia will not the time complexity be N + 26(N) = 27N ??

    • @psinity
      @psinity 6 หลายเดือนก่อน

      i agree

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

    keep on making such videos, thanks a lot
    Great Content

  • @TARUNRAO-oe8bm
    @TARUNRAO-oe8bm 6 หลายเดือนก่อน +3

    Striver bhaiya, I didnt understand why didnt we update the maxf when we are incrementing l. because the max trip will also change right when we change shorten the length of the subarray from front?

    • @sparksfly4421
      @sparksfly4421 5 หลายเดือนก่อน +2

      you're talking about his most optimal approach, i presume. In that case he didn't modify the maxfreq variable under the inner while loop because we don't need a maxfreq variable less than the current maxfreq variable regardless of the trimmed down substring we have right now. that's because, say, the current length of the substring is lesser but we still have the maxfreq value pertaining to the previous valid substring; in this case we simply would not require to have to check the length and change the consequent letters, we'd just ignore it. And to optimize it further, instead of looping through the letters till we get the valid window of (current_length - max_freq) > k, we could replace it with 'if' to check the condition only once because we can again simply ignore the additional trouble of having to loop through for each invalid checks which striver explains why in the other videos of his

    • @oyeshxrme
      @oyeshxrme 4 หลายเดือนก่อน +1

      @@sparksfly4421 thanks bhai

  • @AradhyaSingh-un8di
    @AradhyaSingh-un8di 3 หลายเดือนก่อน +1

    bro rigorously waiting for your heap playlist..
    pls pls pls plss upload asap..

  • @KshitijTakarkhede
    @KshitijTakarkhede 4 หลายเดือนก่อน +2

    Hey peeps , I didn't get "while loop removing to if" can you please elaborate ( it will help alot)

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

    it was quite tough but understood bhaiya

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 8 หลายเดือนก่อน +2

    public int characterReplacement(String s,int k){
    int[]freq=new int[26];
    char[]ans=s.toCharArray();
    int n=ans.length,l=0,max=0;
    for(int r=0;r

  • @Ultra_InstinctBit.h
    @Ultra_InstinctBit.h 6 หลายเดือนก่อน +1

    can we use use mapping for frequency calculations?

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

    Why I'm not able to understand the time complexity ? There is nested loop but still it is not O(n^2). Why?

  • @dhruvdangi8923
    @dhruvdangi8923 6 หลายเดือนก่อน

    sir what a video this is just amazing 🙏🙌🙌🔻

  • @shashankvashishtha4454
    @shashankvashishtha4454 4 หลายเดือนก่อน +1

    O((n + n)) logic is failing on AABABBB, we cannot because of the while loop directly jump to a point where some ans is missed out, if we write if instead of while (like in logic 3) then it will work.

  • @mradulmaheshwari9353
    @mradulmaheshwari9353 8 หลายเดือนก่อน +4

    Even if you don't update the maxfreq in while loop of left then also it is working smoothly.
    Although thanks for wonderfull series striver .
    code - class Solution {
    public int characterReplacement(String s, int k) {
    int[] hash=new int[26];
    int maxlen=Integer.MIN_VALUE;
    int maxfreq=Integer.MIN_VALUE;
    int l=0;
    int n=s.length();
    for(int r=0;rk){
    char cl=s.charAt(l);
    hash[cl-'A']--;
    l++;
    }
    maxlen=Math.max(maxlen,r-l+1);
    }
    return maxlen;
    }
    }

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

      Why would this work? Also once let's say maxfreq is 3 because of 'A', and then if we remove 'A' from the window how do we update maxfreq from 3 to 2 assuming no other char having freq 3?

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

      ​@@fractionofinfinity842actually we don't need to update the maxf value to the lesser value . Becz if u update it to lesser value like 2 , again it will come under > k while condition .

    • @Rahul_Mongia
      @Rahul_Mongia 6 หลายเดือนก่อน +2

      use if (r-l+1-maxf>k) rather than while

  • @KrishnaChauhan-fo4ky
    @KrishnaChauhan-fo4ky หลายเดือนก่อน

    class Solution {
    public:
    int characterReplacement(string str, int l) {
    int s=0,k=0,longest=0,maxfreq=0;//str consists of only uppercase letters
    int mpp[26];
    while(k

  • @torishi82
    @torishi82 6 หลายเดือนก่อน

    Awesome brother. Understood.

  • @abhaysolanki4417
    @abhaysolanki4417 2 หลายเดือนก่อน

    thanks for this

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

    Did all the questions of sliding windows by myself with the optimal solutions. Just leaving the fruit in basket one.
    Watch the video to know all the possible ways of solving that particular problem ;>
    Easy Peasy Lemon Squeezy 😅

    • @rohang7059
      @rohang7059 2 หลายเดือนก่อน

      Can u give the link plz?

    • @ugthesep5706
      @ugthesep5706 2 หลายเดือนก่อน

      @@rohang7059 which problem solution link?

  • @tejaswaniguttula5961
    @tejaswaniguttula5961 8 หลายเดือนก่อน

    Hi anna....!!!
    I am super excited with your sliding window protocol series. I understood every video till now in this series except this video with the difference between only if condition and inner while loop and its inner for loop. Could you please elaborate it in depth with some specific examples. So, that I can understand the thought process behind it. Please please anna...😊😊😊

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

      Trick is we dont want to minimize our max freq variable to get better result, ie. if we get result for max freq 3 we will continue to look for max freq greater than 3 if it exists and ignore freq less than equal 3. This will eliminate need of freq map scan and also remove while loop if we want to look for better max length.

    • @Aryan-rb3yk
      @Aryan-rb3yk 6 หลายเดือนก่อน

      @@nirmalgurjar8181 aaah i get it now ,thanks i got the 26 for loop part , but not the inner while loop part

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

    can anyone explain how assigning mxfreq = 0 and finding maxfreq in further elements will be help?

  • @AnjanaOuseph
    @AnjanaOuseph 25 วันที่ผ่านมา

    Where can I find the python codes for this problem?

  • @santasanthosh2113
    @santasanthosh2113 2 หลายเดือนก่อน

    brilliant

  • @shreyxnsh.14
    @shreyxnsh.14 หลายเดือนก่อน

    My solution:
    int characterReplacement(string s, int k) {
    // s consists of only uppercase English letters.
    int maxlen = 0, maxf = 0;
    int l = 0, r = 0;
    unordered_map mpp;
    while(r < s.size()){
    mpp[s[r]]++;
    maxf = max(maxf, mpp[s[r]]);
    int changes = (r-l+1) - maxf;
    if(changes > k){
    char ch = s[l];
    mpp[s[l]]--;
    if(mpp[s[l]]==0)
    mpp.erase(s[l]);
    l++;
    }
    maxlen = max(maxlen, r-l+1);
    r++;
    }
    return maxlen;
    }

  • @saketjaiswalSJ
    @saketjaiswalSJ 8 หลายเดือนก่อน +1

    hacker as always thanks bro

  • @anandpandey918
    @anandpandey918 2 หลายเดือนก่อน

    //Bruteforce Approach
    class Solution {
    public int characterReplacement(String str, int k) {
    int maxLength = 0;
    for (int start = 0; start < str.length(); start++) {
    for (int end = start; end < str.length(); end++) {
    String substring = str.substring(start, end + 1);
    int numChangesNeeded = substring.length() - getMaxFrequency(substring);
    if (numChangesNeeded > k) {
    break;
    }
    maxLength = Math.max(maxLength, end - start + 1);
    }
    }
    return maxLength;
    }
    private int getMaxFrequency(String str) {
    int[] freqArray = new int[26];
    int maxFreq = 0;
    for (int i = 0; i < str.length(); i++) {
    freqArray[str.charAt(i) - 'A']++;
    }
    for (int frequency : freqArray) {
    maxFreq = Math.max(maxFreq, frequency);
    }
    return maxFreq;
    }
    }
    //Improved Approach
    class Solution {
    public int characterReplacement(String str, int k) {
    int maxLength = 0;
    int[] freqArray = new int[26];
    for (int start = 0; start < str.length(); start++) {
    for (int end = start; end < str.length(); end++) {
    for (int range = start; range k) {
    break;
    }
    maxLength = Math.max(maxLength, (end - start + 1));
    }
    }
    return maxLength;
    }
    private int getMaxFrequency(int[] freqArray) {
    int maxFreq = 0;
    for (int frequency : freqArray) {
    maxFreq = Math.max(maxFreq, frequency);
    }
    Arrays.fill(freqArray, 0);
    return maxFreq;
    }
    }
    //Good Approach
    class Solution {
    public int characterReplacement(String str, int k) {
    int maxLength = 0;
    int[] freqArray = new int[26];
    for (int start = 0; start < str.length(); start++) {
    for (int end = start; end < str.length(); end++) {
    freqArray[str.charAt(end) - 'A']++;
    int numChangesNeeded = (end - start + 1) - getMaxFrequency(freqArray);
    if (numChangesNeeded > k) {
    break;
    }
    maxLength = Math.max(maxLength, (end - start + 1));
    }
    Arrays.fill(freqArray, 0);
    }
    return maxLength;
    }
    private int getMaxFrequency(int[] freqArray) {
    int maxFreq = 0;
    for (int frequency : freqArray) {
    maxFreq = Math.max(maxFreq, frequency);
    }
    return maxFreq;
    }
    }
    //Better Approach
    class Solution {
    public int characterReplacement(String str, int k) {
    int maxLength = 0, maxFreq = 0, start = 0, end = 0;
    int[] freqArray = new int[26];
    while (end < str.length()) {
    freqArray[str.charAt(end) - 'A']++;
    maxFreq = Math.max(maxFreq, freqArray[str.charAt(end) - 'A']);
    if ((end - start + 1) - maxFreq k) {
    freqArray[str.charAt(start) - 'A']--;
    maxFreq = 0;
    for (int i = 0; i < 26; i++) {
    maxFreq = Math.max(freqArray[i], maxFreq);
    }
    start++;
    }
    end++;
    }
    return maxLength;
    }
    }
    //Further Optimised
    class Solution {
    public int characterReplacement(String str, int k) {
    int maxLength = 0, maxFreq = 0, start = 0, end = 0;
    int[] freqArray = new int[26];
    while (end < str.length()) {
    freqArray[str.charAt(end) - 'A']++;
    maxFreq = Math.max(maxFreq, freqArray[str.charAt(end) - 'A']);
    if ((end - start + 1) - maxFreq k) {
    freqArray[str.charAt(start) - 'A']--;
    start++;
    }
    end++;
    }
    return maxLength;
    }
    }
    //Optimal Approach
    class Solution {
    public int characterReplacement(String str, int k) {
    int maxLength = 0, maxFreq = 0, start = 0, end = 0;
    int[] freqArray = new int[26];
    while (end < str.length()) {
    freqArray[str.charAt(end) - 'A']++;
    maxFreq = Math.max(maxFreq, freqArray[str.charAt(end) - 'A']);
    if ((end - start + 1) - maxFreq k) {
    freqArray[str.charAt(start) - 'A']--;
    start++;
    }
    end++;
    }
    return maxLength;
    }
    }

  • @tarunkr4698
    @tarunkr4698 4 หลายเดือนก่อน +1

    mera ho gya hai dimag kharab iss question se

  • @ramakrishnakcr4417
    @ramakrishnakcr4417 8 หลายเดือนก่อน +1

    understood

  • @forfun8659
    @forfun8659 2 หลายเดือนก่อน

    Wow good question and nice explanation

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

    Where i can find sudo code?

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

    Is the naive or brute force code work properly for all test cases ? IF YES CAN ANYONE FIND ERROR IN MY CODE because It does not satisfy test case 2 of leetcode
    int[] arr = new int[26];
    int maxc = 0;
    int maxl = 0;
    for(int i = 0; i< s.length();i++){
    for(int j = i ; j < s.length() ; j++){
    arr[s.charAt(j) - 'A']++;
    maxc = Math.max(maxc,arr[s.charAt(j)-'A']);
    if( (j - i + 1 ) - maxc

    • @ayushgakre9450
      @ayushgakre9450 6 หลายเดือนก่อน

      int[] arr = new int[26]; should be after first loop bcz in next iteration is should be updated to 0

  • @mansisethi8127
    @mansisethi8127 6 หลายเดือนก่อน

    I didn't understand , why we are doing maxf=0 in the else part. Can someone please explain ?

    • @Aryan-rb3yk
      @Aryan-rb3yk 6 หลายเดือนก่อน

      I guess he did it initially as we was going to check again for the max freq using that 0-26 for loop its not in else everything is in if I guess

  • @vageshnp6792
    @vageshnp6792 3 หลายเดือนก่อน

    what data structure is used to store hashmap please anyone tell me?

    • @editorial9702
      @editorial9702 3 หลายเดือนก่อน

      map or unordered_map in c++

    • @vageshnp6792
      @vageshnp6792 3 หลายเดือนก่อน

      @@editorial9702 is it different from head memory and stack memory

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

    ty sir

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

    why we are doing " -'A' " in hash[S[r]-'A' ????

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

      S[r]-'A' will give a integer value which we will use for indexing in our hash map
      For example if s[r]=B
      So, 'B'-'A'(i.e 66-65(ASCII VALUES OF B AND A) =1)
      So hash[1] will increase

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

    Great bro !

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

    int window3(string& s,int k){ //O(n) most optimal pure O(n) logic
    int i=0;
    int j=0;
    int len=0;
    int max_freq=0;
    vectorfreq(26,0);
    while(j < n){
    freq[s[j] - 'A']++;
    max_freq = max(max_freq,freq[s[j] - 'A']);
    if((j-i+1) - max_freq > k){
    freq[s[i]-'A']--;
    i++;
    // max_freq = 0;//use less
    //max_freq = *max_element(freq.begin(),freq.end());//it will make no sense to calculate max freq here in if part we will get max in next iteration with line: max_freq = max(max_freq,freq[s[j] - 'A']);
    }else{
    len = max(len,j-i+1);
    }
    j++;
    }
    return len;
    }
    this is most optimal logic, max_freq = 0, logic not clear to me and it is even not working with while version of this function, but this one is intuitive and clear.

  • @sibiranganath
    @sibiranganath 3 หลายเดือนก่อน

    Understood

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

    class Solution {
    public:
    int characterReplacement(string s, int k) {
    int n = s.size();
    int l=0,r = 0,maxf = 0,maxlen = 0;
    mapmpp;
    while(rk)
    {
    mpp[s[l]]--;
    l = l+1;
    }
    maxlen = max(maxlen,r-l+1);
    r++;
    }
    return maxlen;
    }
    };

  • @kaustubhagrawal6676
    @kaustubhagrawal6676 3 หลายเดือนก่อน

    too clean

  • @rayhangafoor4204
    @rayhangafoor4204 6 หลายเดือนก่อน

    ugh im not able to understand the maxFreq optimization logic

  • @shivsankarsuthar
    @shivsankarsuthar 6 หลายเดือนก่อน +1

    bhai writing thoda shi se kro , smjh ni aata kya likha h, piche jake dekhna pdta h

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

    28 June 2024 4:49pm

  • @asad_iliyas
    @asad_iliyas 6 หลายเดือนก่อน

    understood++

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

    where is the code in all 3 languages???

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

    US

  • @AkashKumarTiwary-u4b
    @AkashKumarTiwary-u4b 6 หลายเดือนก่อน

    God

  • @yuvikarana7204
    @yuvikarana7204 24 วันที่ผ่านมา

    Striver - The G.O.A.T of DSA 💥

  • @SitaRam-m1i
    @SitaRam-m1i หลายเดือนก่อน +1

    Understood

  • @abhinanda7049
    @abhinanda7049 6 หลายเดือนก่อน

    understood

  • @rlm3227
    @rlm3227 6 หลายเดือนก่อน

    understood

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

    Understood

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

    understood

  • @Shivi32590
    @Shivi32590 4 หลายเดือนก่อน +1

    understood

  • @parth2439
    @parth2439 22 วันที่ผ่านมา

    understood