3298. Count Substrings That Can Be Rearranged to Contain a String II | Weekly Leetcode 416

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ม.ค. 2025

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

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

    Nice explanation! I like the way you optimize the code gradually from brute-force code.

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

    Very easy to understand code structure for c&d 🔥

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

    thnxxx the way u optimize is really awesome, no one do that.

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

    Is there any way to contact you for query in some other questions (not from your videos) ?
    For now, I am mentioning the question here , but it would be great if you create some discussion space.
    Question : Given a tree undirected with n nodes (node i has value v[i]), we define an edge "e" to be good if after removing "e" both subtrees formed have frequency of all values in that subtree

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

    now a days, weekly contests are easy. but biweekly are very tough. pls make videos of bi weekly regularly

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

    Difficult to understand completely. Atleast you have to provide the full code of all methods from bruteforce to optimizations.

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

      Can you help understand which part was difficult, maybe I can simplify?
      Regarding code - I intentionally didn't provide code for initial versions so that you can try our yourself. I am always happy to help find the bugs (or point in the right direction).
      If you don't write code, there is very less value in upsolving because unless you write code you will not know the finer details involved.

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

    Bro, i don't know why you stopped posting videos, if possible kindly resume it, you don't have any idea how much these videos help for people like me, the way you explained step-by-step and 5 methods(my god) is the type of explanation even striver didn't gave in many videos
    It's a request bhai, if possible please continue to post contest questions

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

    Hi mohan, could you please tell me whats wrong in the below code? it passed 749 / 757 cases. The 750th inputs are soo large that I can't do try run to figure out what's wrong.
    class Solution {
    public long validSubstringCount(String word1, String word2) {
    int n = word1.length();
    HashMap w2Map = new HashMap();
    HashMap w1Map = new HashMap();
    for(char ch : word2.toCharArray()){
    w2Map.put(ch,w2Map.getOrDefault(ch,0)+1);
    }
    long ans = 0;
    int cnt = 0;
    int i = 0;
    int j = 0;
    while(j < n){
    char ch = word1.charAt(j);
    w1Map.put(ch,w1Map.getOrDefault(ch,0)+1);
    if(w2Map.containsKey(ch) && w1Map.get(ch) == w2Map.get(ch)){
    cnt++;
    }
    while(cnt == w2Map.size()){
    ans += n-j;
    char ithCh = word1.charAt(i);
    w1Map.put(ithCh,w1Map.get(ithCh)-1);
    if(w2Map.containsKey(ithCh) && w1Map.get(ithCh) < w2Map.get(ithCh)){
    cnt--;
    }
    if(w1Map.get(ithCh) == 0){
    w1Map.remove(ithCh);
    }
    i++;
    }
    j++;
    }
    return ans;
    }
    }