Word Break 2 | Leetcode

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

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

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

    i stumbled upon this channel , one of my best discoveries of the day !!!!

  • @pradeepmehra6879
    @pradeepmehra6879 3 ปีที่แล้ว +6

    Love your way of teaching. I was able to code the solution myself even after watching only 7mins of the video

  • @Pegasus02Kr
    @Pegasus02Kr 3 ปีที่แล้ว +1

    I found your channel a month ago and walkthrough almost all the uploaded videos. Thanks for new uploading!

  • @VikasSharma-eg8mc
    @VikasSharma-eg8mc ปีที่แล้ว

    You explained problem like you have done PhD in it.
    Explained deeply and clearly with every possible concept

  • @serhattural3168
    @serhattural3168 3 ปีที่แล้ว +4

    Best explanation again. I think we can optimize Trie search because for each character we are starting search from root of Trie. if we keep last node, we can continue at current position on Trie. If we find a new word or reach leaf, we can reset to root for new search.

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +2

      Yes we can do that

    • @gladyouseen8160
      @gladyouseen8160 2 ปีที่แล้ว

      @@techdose4u in python trie is implented using dictionary. If we use that concept TC will be O(len(target)+sum of lengths of worddictionary)

  • @coder1015
    @coder1015 3 ปีที่แล้ว +10

    Oh man you're back I can't believe my eyes 😁

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +3

      I will upload don't worry :)

  • @darshansimha2166
    @darshansimha2166 2 ปีที่แล้ว +1

    Hey! I don't see any advantage of using a Trie, because at any point you will be iterating over all the words and most languages have an indexOf method to see if a word is a prefix of a string. So why do the Trie, the TC is anyway 2^N. We literally gained no improvement in the time by using Trie and not to mention we used additional space. I might be wrong. Here is my implementation in Java.
    ``` public List wordBreak(String s, List wordDict) {
    List result = new ArrayList();
    wordBreakHelper(s, wordDict, result, new StringBuilder());
    return result;
    }
    private void wordBreakHelper(String s, List wordDict, List result, StringBuilder current) {
    if (s.equals("")) {
    // We do this because we don't want to add space on the last word
    current.deleteCharAt(current.length() - 1);
    result.add(current.toString());
    return;
    }
    for (String word : wordDict) {
    if (s.indexOf(word) == 0) {
    current.append(word);
    current.append(" ");
    wordBreakHelper(s.substring(word.length(), s.length()), wordDict, result, new StringBuilder(current));
    // We do this because we want to remove the last added space and the last word
    current.delete(current.length() - word.length() - 1, current.length());
    }
    }
    return;
    }
    ```

    • @vinayakgandhi5690
      @vinayakgandhi5690 2 ปีที่แล้ว +1

      I was thinking the same, I think when the complete String needs to be matched, Trie is just overkill. Trie is super powerful when there is prefixes and suffixes involved.

  • @HimanshuKumar-sl6ud
    @HimanshuKumar-sl6ud 3 ปีที่แล้ว +3

    Sir you are great teacher , your way to explain complex things in easy ways fantastic. sir please upload more and more problems solution of leetcode please sir.

  • @paragroy5359
    @paragroy5359 3 ปีที่แล้ว +3

    Nice explanation keep on making such videos.....your content is really amazing

  • @643kanavguleria9
    @643kanavguleria9 ปีที่แล้ว

    upper one seems little complex - this code worked for me when solved in gfg - class Solution{

    public static boolean breakIt(int n ,List al , List dict
    , String s ,String ans , int next)
    {
    // System.out.println(ans+" ---- "+next);
    if(s.length()

  • @shivam4you744
    @shivam4you744 3 ปีที่แล้ว +1

    Happy to see you again sir... ☺😇

  • @ismail8973
    @ismail8973 3 ปีที่แล้ว +1

    After Long time bro. Happy to see you again. Bro can you do some good playlist for system design.

  • @ravishasharma7
    @ravishasharma7 3 ปีที่แล้ว +2

    Hey! This is not related to this question. I got a question in a company's OA and I don't find a solution for it. Can you help? The question is: Given some points of the coordinate plane like (x, y), we need to find the minimum number of straight lines so that all these points get covered. Also, it's similar to LeetCode: 149. I have tried this a lot, can't solve it properly.

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      149 is about max points on just a straight line. We can repeat the algorithm as long as we don't cover all points. I will try it 👍🏼

  • @ayushgoel9584
    @ayushgoel9584 3 ปีที่แล้ว +1

    Hi bro, please make some tutorial for machine coding rounds and low level design, currently there is no content present on such topics

  • @martinharris4416
    @martinharris4416 3 ปีที่แล้ว +2

    after a looong time !!!! where were u?

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +3

      Haha :) Teaching in my LIVE classes :P

    • @martinharris4416
      @martinharris4416 3 ปีที่แล้ว

      @@techdose4u Oh thats nice. I really wanted to join those classes but i already covered alot of the syllabus you mentioned and also i couldn't afford the course. But I'm very happy for you.

  • @coder1015
    @coder1015 3 ปีที่แล้ว +2

    How frequently will u upload

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +1

      Trying for 2 videos per week

    • @coder1015
      @coder1015 3 ปีที่แล้ว

      @@techdose4u pls do video on leetcode546 it's hard to understand and upload hard problems that covers a lot of concepts

  • @palakmantry
    @palakmantry 2 ปีที่แล้ว +2

    Why is the trie more efficient than map?

    • @techdose4u
      @techdose4u  2 ปีที่แล้ว +1

      Map may have collision :)
      TRIE will always find the value in O(string Len) time.

    • @palakmantry
      @palakmantry 2 ปีที่แล้ว +1

      @@techdose4u Thank you so much for your prompt reply, and this is an amazing solution. More power to you and your channel for growing and reaching new heights, best wishes!

    • @vinayakgandhi5690
      @vinayakgandhi5690 2 ปีที่แล้ว

      @@techdose4u Sir, is it possible that even with possible collisions, a Set out performs Trie by big margin as Set is O(1) in average case. I tried solving with both Set and Trie and difference is more than 10 times. (better than 83% using Set and just 12% with Trie)

  • @kubermanitripathi3445
    @kubermanitripathi3445 ปีที่แล้ว

    where you define ans ?