Word Break | Dynamic Programming | Leetcode

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

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

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

    Using a dp array, you could bring down the space complexity from O(n^2) down to O(n). Time complexity remains O(n^3).

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

    Nobody:
    Tech dose: uploads at 3:30 AM😂

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

    Whenever i search better solution i always use to check is there any video from @tech dose

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

    i watched almost all of your videos and they really improved my problem solving skills a lot, I don't fear graphs, tries and heaps anymore, Thank you for that.

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

      but google SDE role test is today

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

      @@yashgandhi9698 so? they've got a thousand interviewer there, pretty sure someone facing some kind of interview each day. LOL

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

    Although i have solved this problem earlier still i was excited to see this video.. that's the level of your teaching skills..you explain stuffs in a very precise and streamlined manner..Thanks for all your explanations.

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

      Great ❤️

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

      Yes he is best in this field till now, always making extra examples and effort to explain. Other youtubers dont give examples

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

      @@techdose4u Since you have not given the solution. I have coded it by myself. Can you tell the error it's not working for cases when we can use strings in the dictionary again
      class Solution {
      public:
      bool wordBreak(string s, vector& wordDict)
      {
      int n = s.length();
      unordered_setm(wordDict.begin(),wordDict.end());
      int dp[n][n];
      for(int g=0 ;g

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

    Rather than using the substr function, we can push each character at a time into a segmented string initialized with an empty string. This will bring down the complexity to O(n^2)

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

      N^2 log(K) to check in the dictionary

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

      @@abhishekchoudhary5713 UNORDERED SET WOULD BRING DOWN SEARCH TIME TO 0(1)
      HENSE 0(N*N)

  • @karan-xm5tj
    @karan-xm5tj ปีที่แล้ว +2

    I understood something from others videos after seeing yours every thing seems to be confusing

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

    wow, loved the explanation and the way you arrived at the most optimal solution. Thanks for the videos, keep them coming :)

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

    I watched your entire DP Playlist. It really helped a lot. Thanks for creating such quality vedios. Hoping for more vedios like this.

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

    Great explanation Sir !! Sir, I think you forgot to attach the code link. Can you plz share it ?

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

    Typo. First approach
    s.substr(pos, i+1)

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

    Really nice explanation, it must have taken a lot of efforts and hardwork. Thanks a lot!!

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

      Thanks. Yes it did 😅

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

    Thanks man, best explaination for this question on utube

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

    the best thing is you r focusing on intuition rather than code.

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

    Great. Working even at night

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

      I think he scheduled it at AM instead of PM😂

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

      Yea. Just got time now after my LIVE classes 😅

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

      @@sainathsingineedi2922 it's not scheduled man 😂

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

    i didn't get the memoization solution why you are doing i-pos+1 let say if pos is 3 the first substring will now from pos (i.e 3) to (i-pos+1 ==
    3 - 3 +1 = 1 ) how can be substring end value is smaller than the starting value it will surely give error

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

      yes, I was thinking the same. I guess there should be s.substring(pos,i+1)

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

    Your explanation is always clear and easy to understand. I've learned a lot. :) But... could you please also do binary search problems? It's quite hard to figure out why I need to solve the problem with binary search. For example, Leetcode 774 Minimize Max Distance to Gas Station. I want to know about your thinking process when you encounter hard binary search problems! Anyways thank you always Techdose, I hope you gain more subscribers soon! You deserve more and more.

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

      Thanks :)
      Noted

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

    so sir in the Backtracking approach also we are creating substring every time so should Not the Time complexity be O(2^N * N ) this multiple of N for creating substring every time?? As its is N^2 * N is Dp memoization approach

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

    Thanks!

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

    Variation of Matrix chain multiplication. Great explanation.

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

    Brute force, better for loop variable:
    class Solution {
    private Set dictSet = new HashSet();
    public boolean wordBreak(String s, List wordDict) {
    for(String str : wordDict) {
    dictSet.add(str);
    }
    return wordBreakRecur(s, 0);
    }
    private boolean wordBreakRecur(String s, int pos) {
    if(pos == s.length()) return true; //whole string has passed.
    //all substrings starting at 'pos', ending at all possible end and
    //wordBreakRecur on s from next position of matched word.
    for(int end = pos + 1; end

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

    Most waited solution from you channel bhaiya

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

    s.substr(pos,i-pos+1) is wrong suppose pos = 4 , it will be s.substr(4,1) which will throw index out of bound exception

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

    The DP solution is hard to understand in my opinion. Its much simpler than what it explained.

  • @study-dq9do
    @study-dq9do 3 ปีที่แล้ว

    Thanks sir..i was able to solve it just after 9 minutes watch..it was that great! Thanks a lot

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

    What do you use to write these things clearly. Like what software and what gadget?

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

    Thanks a ton! This was a great explanation!

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

    Great explanation. Thanks

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

    Sir finally you are back....now keep posting videos on regular basis... really appreciate your efforts ❤️

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

      Thanks. I was always there

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

    and why did you create the String t? if you are not using it? at 16:40

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

    18:50 How is time complexity O(N^2) for the recursion after memoization? Can someone please tell.

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

    what is the advantage of using dp here, like we get a o(n^3) solution here , but by using a map i can get an o(nlogn) solution in the average case

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

    23:10 is the time where you will get goose bumps.

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

    Trie solution would probably be trivial but this was ingenious! thanks.

  • @DK-ox7ze
    @DK-ox7ze 3 ปีที่แล้ว

    Nice video, but I didn't understand one thing: if you are recursively evaluating left and right partition with "&&", then even a single false should cause the entire operation to return false, because true && false is false. So how are we getting true at the end inspite of having few false evaluations in between?

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

    10:03 why it is 2^N? Each point can have more than 2 branches, so it should be N^N isn't it?

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

    Hi Tech dose I see that the code link is empty. Do you plan to add it as you normally do or it won't be the case for this video.
    BTW awesome video as usual, thank you very much

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

      Ohh....I forgot to add. Let me add it now. Thanks for reminding.

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

    Where is the code link?

  • @GrowwMen
    @GrowwMen 12 วันที่ผ่านมา

    Thanks

    • @techdose4u
      @techdose4u  12 วันที่ผ่านมา

      welcome

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

    Bhaiya can you please make video on Word wrap problem also? I am really struggling with it

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

    Good One!

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

    Thank you sir , good explanation

  • @AbhishekKumar-sf6no
    @AbhishekKumar-sf6no 3 ปีที่แล้ว +1

    Great approach bro 🤩🤩🤩

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

    Loved you videos on DP. By the way if you get free time for making videos then please make a video on flip the string into monotone increasing leetcode problem I think I need to understand better...Thanks for teaching us these valuable things...

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

    how did you analyse the time complexity at 16:41

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

    Thanks sir i was waiting for this question ..

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

    in question its mentioned one or more subsrings not all

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

    CAN SOMEBODY TELL ME THE SOFTWARE NAME FOR THIS BLACK SCREEEN.

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

    I guess using a linear dp we can do it in O(n^2) time instead of O(n^3) time complexity.

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

    how are you sure that when pos == s.length, it will be valid string? the whole string also might not be in the dictionary right?

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

    Very much similar to palindrome partitioning

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

    Why do we need String t in the backtracking approach?

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

    please make a video on valid permutations of DI sequence from leetcode dp hard

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

    One day i will try to copy whole your video content and translate into my mother tongue 😀.

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

    what happens to time complexity when we use memorization for n^3 time complexity

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

    Good video. Where's the code link?

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

      Forgot to update 😅

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

      @@techdose4u sir...how to approach these problems...I tend to forget them..please help

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

      class Solution {
      public:
      bool wordBreak(string s, vector& wordDict) {
      setst(wordDict.begin(),wordDict.end());
      int n=s.length();
      bool dp[n][n];
      memset(dp,false,sizeof(dp));
      for(int w=0;w

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

    Could you please upload the code for this problem

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

    Why is memoization complexity n^2 ?

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

    where are the code links ?

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

    Hi, can you please make a video on Median in row wise sorted matrix?

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

    how it is a backtracking?

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

    I wish you added the code link

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

      I will add it :)

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

      @@techdose4u sure. I am gonna code it according to your explanation. If works, i will add in the comment.
      Also, as a optimization, we are only concerned about the first row of dp. So we can optimise space complexity.

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

    I don't see how memo helps as the result stored in memo will only be used once (when evaluated) and never be re-used, say there is a valid sentence ilikemango, the call stack is like this
    wb(i)
    / \
    true wb (like)
    / \
    true wb(mango)
    / \
    true true
    so where is the memo helping as a cache & preventing recomputation?

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

    Sir code link?

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

    osssum!!!!!!!!!

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

    Sir plz share the code link??

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

    just mcm variation

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

    your intuitive approach fails at this test case
    "aaaaaaa"
    ["aaaa","aaa"] at 7:10

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

    getting index out of bound error

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

    Waiting for DP with Bitmasking !

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

    DP appraoch code is not working , please check ( java), i have done in java
    only this part was changed
    Set set = new HashSet();
    for(String word:wordDict){
    set.add(word);
    }

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

    code link??

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

      class Solution {
      public:
      bool wordBreak(string s, vector& wordDict) {
      setst(wordDict.begin(),wordDict.end());
      int n=s.length();
      bool dp[n][n];
      memset(dp,false,sizeof(dp));
      for(int w=0;w

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

    DP solution could be solved using 1D. You made it complicated by using 2D Array.

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

  • @DEVENDERKUMAR-pg2nq
    @DEVENDERKUMAR-pg2nq 3 ปีที่แล้ว +1

    but we have to solve qustion in O(N*N) time complaxity anyone give my idea about it🤩🤩🤩

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

    What if dictionary=["pen", "penny", "wise"] and word is "pennywise"

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

      Rewatch the video :)

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

      Yes I also had this doubt

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

      @@coder1015 first we will choose pen and then will backtrack and choose penny instead ;)

  • @amitabhbacchan-cz5ou
    @amitabhbacchan-cz5ou ปีที่แล้ว

    Kya samjhate ho bhai kuch samjh nhi ata jab english acche se nhi ati to hindi me samjaho na yr

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

    worst explanation. You should explain it lil short and crisp. too much information also will confuse.

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

    Your explanations are tedious, just get to the point man. You repeat obvious things so many times and just prolong it so much it's just annoying.

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

    i do not understand anything by watching this video please everyone don't watch his video because he gives very poor explanation

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

    Worst explanation ever