Leetcode Biweekly Contest 142 | 3331. Find Subtree Sizes After Changes | Codefod

Поделиться
HTML-код
  • Опубликовано: 5 ноя 2024

Комментарии • 12

  • @niteshsaxena1066
    @niteshsaxena1066 10 дней назад

    you explain very well....please keep on bringing these editorials....and please provide link to your submission

    • @codefod
      @codefod  10 дней назад

      Thanks! Added link in description

  • @DEEPAKDESHMUKH-q2r
    @DEEPAKDESHMUKH-q2r 10 дней назад +2

    iincrese volume

  • @Anuj-vf7bg
    @Anuj-vf7bg 8 дней назад +1

    giving tle in 1 case

    • @codefod
      @codefod  6 дней назад

      It's working. You might have written something wrong

    • @Anuj-vf7bg
      @Anuj-vf7bg 6 дней назад +1

      @ I copied and pasted your code 631/632 passsed

    • @Anuj-vf7bg
      @Anuj-vf7bg 6 дней назад

      New test case has been added

    • @ayushkumar-ew9wu
      @ayushkumar-ew9wu 5 дней назад

      It show Tle in last two testcases

  • @deathrider4897
    @deathrider4897 3 дня назад

    this sol does not give tle
    class Solution {
    public:
    void dfs(vector& adj,string& s,vector& newadj,vector& parentCharCnt,int u){
    for(int v:adj[u]){
    int CharIndex = s[v]-'a';
    if(parentCharCnt[CharIndex].size()>0){
    int NearAncestorIndex = parentCharCnt[CharIndex].size()-1;
    newadj[parentCharCnt[CharIndex][NearAncestorIndex]].push_back(v);
    }
    else{
    newadj[u].push_back(v);
    }
    parentCharCnt[CharIndex].push_back(v);
    dfs(adj,s,newadj,parentCharCnt,v);
    parentCharCnt[CharIndex].pop_back();
    }
    }
    int CountDescendantsDfs(vector& np,int u,vector& ans){
    ans[u] = 1;
    for(int v:np[u]){
    ans[u]+=CountDescendantsDfs(np,v,ans);
    }
    return ans[u];
    }
    vector findSubtreeSizes(vector& parent, string s) {
    int n = parent.size();
    vector ans(n,0);
    vector adj(n);
    vector newadj(n);
    vector parentCharCnt(26);

    for(int i=1;i

  • @KinjalGupta-ts2cz
    @KinjalGupta-ts2cz 9 дней назад

    increase volume