Sum of Prefix Scores of Strings - Leetcode 2416 - Python

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

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

  • @adityamwagh
    @adityamwagh 14 วันที่ผ่านมา +6

    I coded the optimal solution all by myself (without referring to the coding part of the video). Neet has designed his DSA course in in wonderful way. The video on PrefixTree definitely helped me!

  • @dhyeyparekh4994
    @dhyeyparekh4994 14 วันที่ผ่านมา +2

    I loved the way you go from brute force to optimal thinking step by step. Great explanation

  • @jamestwosheep
    @jamestwosheep 14 วันที่ผ่านมา +2

    I just wanted to express how grateful I am to your video explanations. I managed to go straight to that optimal solution with this one on my first attempt thanks in very large part to your previous explanations about prefix trees. I had relatively slow runtime too with my Javascript submission, but I suspect that may be because LeetCode might occasionally adds additional test cases over time to some of their problems.

  • @AKProductionsTelugu
    @AKProductionsTelugu 14 วันที่ผ่านมา +1

    Using a hashmap for the same trie approach seems to be working good with time complexity

  • @_PranavDesai
    @_PranavDesai 14 วันที่ผ่านมา +3

    i suppose another optimisation would be to store the count of each prefix in a hashmap.

  • @SergeyAngelov
    @SergeyAngelov 14 วันที่ผ่านมา +1

    Sometimes I wonder what is the logic of problem classification. I would put it between easy and medium. There are a lot of medium problems that are way harder than this one. Literally took couple minutes to understand what is needed and couple minutes to code optimal solution using Trie.

  • @sauravsingh4497
    @sauravsingh4497 14 วันที่ผ่านมา +1

    I was using the older version of leetcode on phone so couldn't see the difficulty level of the problem I solved it on phone using trie
    Didn't realise it was a hard problem.If I knew it was a hard problem I would have fumbled

  • @ramennudeln247
    @ramennudeln247 14 วันที่ผ่านมา

    Those faster examples use a dict instead of a list in the TrieNode class which saves time and operations, it would seem.

  • @MP-ny3ep
    @MP-ny3ep 14 วันที่ผ่านมา

    One of your best explanations. Thank you so much!

  • @ajitpalsingh606
    @ajitpalsingh606 14 วันที่ผ่านมา +5

    I did with hashmap 36/38 passed

  • @karthi7102
    @karthi7102 14 วันที่ผ่านมา

    Thank you, explanaation was great.

  • @vijethkashyap151
    @vijethkashyap151 14 วันที่ผ่านมา

    BEAUTIFUL ! 💖

  • @jitpatel7692
    @jitpatel7692 14 วันที่ผ่านมา

    Thank you,great explanation

  • @SarweshParsewar
    @SarweshParsewar 14 วันที่ผ่านมา +1

    Day 1 of asking to upsolve leetcode contest problems🤖

  • @anandsrikumar007
    @anandsrikumar007 14 วันที่ผ่านมา

    This is yesterday's problem only. Only small change is there.

  • @matheuscosta5330
    @matheuscosta5330 14 วันที่ผ่านมา

    Nice!

  • @vanshraj4724
    @vanshraj4724 14 วันที่ผ่านมา

    can someone tell why using vector gave mle but not ehen using array in cpp using Trie method

  • @hasferrr
    @hasferrr 9 วันที่ผ่านมา

    some people say its easy. yes it is easy to implements but hard to figure out :)

  • @GursimranMatharu
    @GursimranMatharu 14 วันที่ผ่านมา

    why there are guitars in the thumbnail 😭

  • @steco5441
    @steco5441 14 วันที่ผ่านมา +2

    Call variables pointers on purpose man please!!!!!! It could be a great inside joke

  • @_lax.man_5473
    @_lax.man_5473 14 วันที่ผ่านมา

  • @aashishbathe
    @aashishbathe 14 วันที่ผ่านมา +12

    This was in no way a hard problem lol, if someone knows Trie then its a medium at max.

  • @anshdholakia714
    @anshdholakia714 14 วันที่ผ่านมา

    I still dont get how the brute force solution is O(n^2.L^2)

    • @professorpoke
      @professorpoke 14 วันที่ผ่านมา

      First tell me what is the complexity according to you. Then we can discuss further.

    • @dekumidoriya-qi2is
      @dekumidoriya-qi2is 14 วันที่ผ่านมา

      see it like this for comparison two loops -> O(n^2)
      and for generating prefix -> O(L^2) beacause slicing is a O(n) operation
      so TC -> O(n^2.L^2)

    • @cineaddict1633
      @cineaddict1633 13 วันที่ผ่านมา

      @@dekumidoriya-qi2is in python slicing is o(1) operation

    • @dekumidoriya-qi2is
      @dekumidoriya-qi2is 12 วันที่ผ่านมา

      @@cineaddict1633 technically the complexity is not exactly O(1) it is O(k) where k is the size of slice
      ref - wiki.python.org/moin/TimeComplexity

  • @sanjeevmurmu6505
    @sanjeevmurmu6505 14 วันที่ผ่านมา

    i am trying to implement this solution in javascript but i am getting time limit exceeded on 37th testcase words=["bfiaaaaifb","aaaaooaaaa"] can anybody tell me how to optimize this further for javascript.

    • @muditkalra7077
      @muditkalra7077 14 วันที่ผ่านมา +1

      yes i am also facing tle in js , i implement both approach (hashmap and trie) got tle on both solution!
      Edit 1: I don't know why but i replace one for loop(getScore loop) with map and it somehow got accepted !

  • @Sharky-1507
    @Sharky-1507 14 วันที่ผ่านมา

    3rd

  • @chaitanyasharma6270
    @chaitanyasharma6270 14 วันที่ผ่านมา

    the first solution doesnt submit in java
    class Solution {
    public int[] sumPrefixScores(String[] words) {
    Map map = new HashMap();
    for(String w:words){
    for(int i=w.length();i>=1;i--){
    String sub = w.substring(0,i);
    map.put(sub,map.getOrDefault(sub,0)+1);
    }
    }
    int[] res = new int[words.length];
    for(int i=0;i=1;j--){
    String sub = w.substring(0,j);
    c+=map.get(sub);
    }
    res[i]=c;
    }
    return res;
    }
    }
    how does leetcode even calculate the times?!

    • @AshwinRB-yi3kf
      @AshwinRB-yi3kf 14 วันที่ผ่านมา +1

      I tried a similar approach in c++, it doesnt get accepted too. Might have to do with how different languages handle string operations, idk

    • @chaitanyasharma6270
      @chaitanyasharma6270 14 วันที่ผ่านมา

      @@AshwinRB-yi3kf or maybe they compile our codes again and again for each test case but that seems pointless

    • @axelcool1234
      @axelcool1234 14 วันที่ผ่านมา +1

      @@chaitanyasharma6270 I'm pretty sure the only reason the Python solution passes is due to Python being given longer time to complete due to how slow the language is. I submitted a hashmap solution in Rust, and Rust's string slicing is constant time. I still TLEd.

  • @aashishbathe
    @aashishbathe 14 วันที่ผ่านมา

    0 views xD

  • @sri_harsha_dv
    @sri_harsha_dv 14 วันที่ผ่านมา

    9:00 did you mean to actually trie it?