word break | word break leetcode interviewbit | leetcode 139 | recursive top down dp | september
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
I like the way you first explain the brute force approach and then try to move towards the best case solution.:
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.
Very nicely explained 👍. I have searched so much to get proper explanation until I found you.
Glad to hear that! Keep learning and sharing.
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
Thank and welcome to channel.
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.
True, thanks and welçome
inside the if cond, shouldn't it be map.put(left) instead of the entire input string 's'
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.
very clean, I didn't really understand the question till watched your video. Thank you!
Glad it helped!
if you get TLE make sure the map/hashmap line is outside of the method.
You are a god.
thanks for explaining!
Happy to help!
way better explanation than leetcode premium
Sir thank you for the amazing explanation.It is really helpful.
Thanks and welcome to channel.
11:10 how is space complexity O(1) if you are doing recursive call and there is also a map?
You correct my mistake Space Complexity is not O(1)
Good Explanation
Great video. Great explanation. Thanks.
Glad you enjoyed it!
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?
yes, brute force is exponential time complexity.
Great explanation man!
Glad it helped!
Isn't it adding some extra time factor if we are using substring ?
What is the other option do you think more better?
awesomee solutionn thnk u soo much sir
Thanks and enjoy coding.
Excellent Explanation ✌✌
Glad it was helpful!
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
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]
@@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
Great
thanks
Why we use map map doesnt alllow duplicate character
Re-use the solution of the similar sub-problem so that we can avoide recomputaton of same subproblem.
It throws up TLE even after using map for me which is weird..
Share you code.
decare Map as a private variable under class, outside the function.
Why are we using the for loop from i = 1 to i = length of the string. Can u please elaborate.
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.
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.
Why i
Can you also plz cover how to calculate Time and Space Complexity
Recursive is Exponential time and DP is O(n^3).
@@NareshGupta looking for separate lecture of how to find Time and Space complexity of any program with some example.
Thanks for your response
@@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.
It throws up TLE even after using map for me which is weid..
Complexity Ananlysis
Recursive - TC - O(N * 2^N), SC - O(N)
DP - TC - O(N^3), SC - O(N)
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).
@@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
make a video to explain the time complexity terms
how are we getting N*2^N for recursive approach. and N^3 for DP.
This solution is still giving TLE . check it, its not working , WASTE OF TIME