word break | word break leetcode interviewbit | leetcode 139 | recursive top down dp | september

Sdílet
Vložit
  • čas přidán 25. 09. 2020
  • Problem Link - leetcode.com/problems/word-br...
    www.interviewbit.com/problems...
    Subscribe for more educational videos on data structure, algorithms and coding interviews - czcams.com/users/NareshGupta?s...
    Code Repository - github.com/naresh1406/youtube...
    LinkedIn - / nareshiitg
    Instagram - / naresh_gupta_
    Facebook - / 2784412725174003
    Quora - qr.ae/pN2M0x
    #DP #Recursive #TopDown #WordBreak #Word #LeetCode #InterviewBit #Problem139 #Coding #Programming #Interview #Practice #DataStructure #Algorithm #Java #Preparation #NG #nickode #cct #cook_code_travel #september

Komentáře • 58

  • @swapaher
    @swapaher Před 3 lety +5

    I like the way you first explain the brute force approach and then try to move towards the best case solution.:

    • @NareshGupta
      @NareshGupta  Před 3 lety +5

      Actually, at-least one should come-up with brute force solution is very important then only you will know difference between brute force and optimal solution and how to derive optimal solution from brute force.

  • @kumarshivam2010
    @kumarshivam2010 Před 3 lety +1

    Very nicely explained 👍. I have searched so much to get proper explanation until I found you.

    • @NareshGupta
      @NareshGupta  Před 3 lety +1

      Glad to hear that! Keep learning and sharing.

  • @pressplay493
    @pressplay493 Před 2 lety +1

    Bro , I watched 10 videos but was not able to understand the DP solution , I was able to come up with recursive one. Your video is crisp yet clear. Thanks man , you are a saviour. subscribed

  • @drewvananne1796
    @drewvananne1796 Před 3 lety +4

    Great explanation! Dynamic programming can be so confusing if you try to find the most efficient solution at the start. This is so much more clear when you find the recursive problem, see if there are repeating sub problems, and cache the answers to these repeated problems to optimize it.

  • @thepardhu100
    @thepardhu100 Před 2 lety +1

    inside the if cond, shouldn't it be map.put(left) instead of the entire input string 's'

  • @lany5059
    @lany5059 Před 3 lety +1

    Thanks for the great explanation! Really helpful, just wondering how should this problem approached if we do it bottom-up? I am still a bit iffy between these two.

  • @th2315
    @th2315 Před rokem

    very clean, I didn't really understand the question till watched your video. Thank you!

  • @jcontradiction
    @jcontradiction Před 10 měsíci +2

    if you get TLE make sure the map/hashmap line is outside of the method.

  • @sauravneupane5054
    @sauravneupane5054 Před rokem

    You are a god.

  • @raj_kundalia
    @raj_kundalia Před rokem

    thanks for explaining!

  • @ExponentialTransduction
    @ExponentialTransduction Před 10 měsíci

    way better explanation than leetcode premium

  • @saurabhgupta4082
    @saurabhgupta4082 Před 3 lety +1

    Sir thank you for the amazing explanation.It is really helpful.

  • @MayankSingh_is_me
    @MayankSingh_is_me Před 3 lety

    11:10 how is space complexity O(1) if you are doing recursive call and there is also a map?

    • @NareshGupta
      @NareshGupta  Před 3 lety +1

      You correct my mistake Space Complexity is not O(1)

  • @imranimmu4714
    @imranimmu4714 Před 11 měsíci

    Good Explanation

  • @abhijitbiradar
    @abhijitbiradar Před rokem

    Great video. Great explanation. Thanks.

  • @rohandsouza9147
    @rohandsouza9147 Před 3 lety +2

    Thank you so much for this video, after spending a day on this problem I finally understood the solution!! Also can anyone pls explain why the tc of bruteforce approach is exponential and is it 2^n?

    • @NareshGupta
      @NareshGupta  Před 3 lety

      yes, brute force is exponential time complexity.

  • @ritikmishra3643
    @ritikmishra3643 Před 3 lety +1

    Great explanation man!

  • @vishalgoel6323
    @vishalgoel6323 Před 3 lety +1

    Isn't it adding some extra time factor if we are using substring ?

    • @NareshGupta
      @NareshGupta  Před 3 lety

      What is the other option do you think more better?

  • @sharuk3545
    @sharuk3545 Před 3 lety +1

    awesomee solutionn thnk u soo much sir

  • @neetishmaurya6618
    @neetishmaurya6618 Před 3 lety +1

    Excellent Explanation ✌✌

  • @saurabhgupta4082
    @saurabhgupta4082 Před 3 lety +3

    Sir i have one request that can you please make one video on scatter palindrome. A string is a scatter palindrome if its letters can be rearranged to form a palindrome. We have to determine how many substrings of a given string are scatter palindrome.
    example :- given string is "aabb"
    output :-9
    ["a","aa","aab","aabb","a","abb","b","bb","b"]
    Note:- substrings which are equal but are presesnt at different positions in a string is considered different. example "a" at 0 is considered different from "a" at 1

    • @NareshGupta
      @NareshGupta  Před 3 lety +1

      Interesting Question. Bit busy schedule these days, but I will try my best to find time.
      What did you tried so far? [At-least try and come-up with the Naive Solution]

    • @saurabhgupta4082
      @saurabhgupta4082 Před 3 lety

      @@NareshGupta According to me this matrix chain multiplication format problem. I got stuck at how to check whether a string if rearranged can form a palindrome. This question was asked to me in coding test of nference company(12 lakhs package) but i got stuck at it.
      2nd question was the variation of unbounded knapsack which i solved

  • @dipeshupadhyaya5130
    @dipeshupadhyaya5130 Před 2 lety

    Great

  • @navinchainani4721
    @navinchainani4721 Před rokem

    Why we use map map doesnt alllow duplicate character

    • @NareshGupta
      @NareshGupta  Před rokem

      Re-use the solution of the similar sub-problem so that we can avoide recomputaton of same subproblem.

  • @harshavardhanm7091
    @harshavardhanm7091 Před 3 lety +1

    It throws up TLE even after using map for me which is weird..

  • @yogeshmeshram7735
    @yogeshmeshram7735 Před 3 lety

    Why are we using the for loop from i = 1 to i = length of the string. Can u please elaborate.

    • @NareshGupta
      @NareshGupta  Před 3 lety +1

      We have to try all the words starting from first character. As, substring method don't include right bound character s.substring(0, i) --> returns substring s[0 ... i - 1].
      But if you want to run loop from i = 0 to i < length - you just need to update i --> i + 1 in substring calls.

  • @DK-ox7ze
    @DK-ox7ze Před 2 lety

    In line number 10, you are doing "&&" for left and right parts, so if any such evaluation returns false, the answer should also be false. But how are you getting true at the end, inspite of having some false returns? Because false && true is false.

  • @SahilSingh-pc1vd
    @SahilSingh-pc1vd Před 2 lety

    Why i

  • @shadab5azhar
    @shadab5azhar Před 3 lety

    Can you also plz cover how to calculate Time and Space Complexity

    • @NareshGupta
      @NareshGupta  Před 3 lety

      Recursive is Exponential time and DP is O(n^3).

    • @shadab5azhar
      @shadab5azhar Před 3 lety +1

      @@NareshGupta looking for separate lecture of how to find Time and Space complexity of any program with some example.
      Thanks for your response

    • @NareshGupta
      @NareshGupta  Před 3 lety +2

      @@shadab5azhar Yes, I am thinking that from long time but I'm lazy guy too.
      I will try to make some useful video on complexity determination in coming day.

  • @harshavardhanm7091
    @harshavardhanm7091 Před 3 lety

    It throws up TLE even after using map for me which is weid..

  • @NareshGupta
    @NareshGupta  Před 3 lety +1

    Complexity Ananlysis
    Recursive - TC - O(N * 2^N), SC - O(N)
    DP - TC - O(N^3), SC - O(N)

    • @ThePradeep2010
      @ThePradeep2010 Před 3 lety

      Can you provide explanation of time complexity. It will be great to have them at end of each solution in the video. In video you mentioned time complexity is O(N^2) but here you have written as O(N^3).

    • @rohandsouza9147
      @rohandsouza9147 Před 3 lety

      @@ThePradeep2010 if you want N^2 then store dictionary in a hashset, hashset.contains is of O(1) complexity,
      so it will effectively reduce N^3 to N^2

    • @master_persi
      @master_persi Před 2 lety

      make a video to explain the time complexity terms
      how are we getting N*2^N for recursive approach. and N^3 for DP.

  • @rohandevaki4349
    @rohandevaki4349 Před rokem

    This solution is still giving TLE . check it, its not working , WASTE OF TIME