Word Break Problem using Backtracking | Word Break Solution in JAVA

  Рет қаралды 31,403

Pepcoding

Pepcoding

Күн бұрын

Пікірлер: 71
@ankitbatra9832
@ankitbatra9832 3 жыл бұрын
Nice solution sir! I would like to add one point here: the answer strings will always have an extra space character at the end, so if we want to avoid that, we will need to pop back the character from string before printing our answer.
@MGtvMusic
@MGtvMusic 3 жыл бұрын
Yes exactly,I just used ans.substring(0,ans.length()-1)
@manpreetsinghrana7751
@manpreetsinghrana7751 Жыл бұрын
use s.trim() before you display the result. It will clear all white spaces after the string
@jaivishwakarma304
@jaivishwakarma304 Жыл бұрын
when u r cpp coder but still watches his video because of quality explanation
@deeptarkoroy6724
@deeptarkoroy6724 3 жыл бұрын
Thanks sir.I did this ques without watching the video,its all because of u.
@Pepcoding
@Pepcoding 3 жыл бұрын
Glad to hear that Keep learning, Keep growing and keep loving Pepcoding!😊
@vikkasmaheshwari862
@vikkasmaheshwari862 2 жыл бұрын
Isme right string bnane ki bjaye hm index pass kr skte hai
@jatinkumar4410
@jatinkumar4410 2 жыл бұрын
Very nice explanation sir. I have a doubt. It is normal recursion right? Then why is it considered in backtracking? Also please explain its time and space complexity...
@harmanjeetsingh3556
@harmanjeetsingh3556 2 жыл бұрын
Your are my fav teacher sir!! i dont like to watch others video anymore
@shrutiemu
@shrutiemu 4 жыл бұрын
Sir your explanation is phenomenal and it gives clarity to the thinking process. But I faced certain time limit exceeded scenarios when the input is too huge .How can we handle such scenarios using recursion
@Pepcoding
@Pepcoding 4 жыл бұрын
beta DP ki hongi. Recursion ke baad DP mei convert karna hoga
@arvindsinha1566
@arvindsinha1566 3 жыл бұрын
I faced same issue of time exceed. I solved using memoization technique without using DP
@harmanjeetsingh3556
@harmanjeetsingh3556 2 жыл бұрын
@@arvindsinha1566 it gives in gfg, use top down approach with memorization instead of tabulation, it will save some calls, here we are finding every combination, time complexitywise both are same
@bluesteel1
@bluesteel1 Жыл бұрын
Thanks sir. Neat explanation
@bibhusingh2
@bibhusingh2 4 жыл бұрын
When was the Sumeet sir next Webinar.? . Because i really need to talk to him! Please sir take a next Webinar as soon as possible.🙏
@Pepcoding
@Pepcoding 4 жыл бұрын
aj sham 7 bje ek mock interview types hai
@bibhusingh2
@bibhusingh2 4 жыл бұрын
@@Pepcoding Sir KZbin par yaa Zoom, agr zoom par h toh link send kar dijiye!
@ajayjangid5968
@ajayjangid5968 3 жыл бұрын
Jai Hind sir... Your are doing ✌️✌️✌️
@Pepcoding
@Pepcoding 3 жыл бұрын
Jai hind
@arpanbanejee5143
@arpanbanejee5143 3 жыл бұрын
Sir, iska memoized version pls bata dijiye, sab jagah bottom up kie hua hian
@ajayjangid1164
@ajayjangid1164 3 жыл бұрын
Nice explanation👌
@pravinmudaliyar3421
@pravinmudaliyar3421 4 жыл бұрын
Sir , isme backtracking kaha ho rha h! Kahi pe bhi backtrack code nhi likha hua ? Btw ... Your teaching is just amazing. Thankyou sir🙏
@Pepcoding
@Pepcoding 4 жыл бұрын
beta, title misleading hai. recursion and backtracking ka group hai. kuch swaal sirf recursion ke hain.
@joyd6609
@joyd6609 3 жыл бұрын
great explanation sir
@sudhanshukumar1558
@sudhanshukumar1558 4 жыл бұрын
It's time complexity is T=O(2^n)
@LegitGamer2345
@LegitGamer2345 3 жыл бұрын
n power n
@LegitGamer2345
@LegitGamer2345 3 жыл бұрын
n options n levels
@yatinarora1252
@yatinarora1252 3 жыл бұрын
Its basically taking the length of string and cutting it by length of left substring so total will be n power n and space is basically of length of substring basically n times and calculating it by n times
@Sajju_01
@Sajju_01 2 жыл бұрын
It is only recursion not backtracking right??
@nilufaislam4768
@nilufaislam4768 4 жыл бұрын
Sir what is the time and space complexity? And can we use dp here to store the intermediate results and improve the time ?
@Pepcoding
@Pepcoding 4 жыл бұрын
time complexity exponential. Yes we can use DP. That video will be posted soon.
@sharmamukul938
@sharmamukul938 4 жыл бұрын
I don't think this approach works for all possible cases. It works for cases when a word is of form str.substring(0,i+1) but fails when words are present in the form str.substring(i,j) ,i.e when words are present between the sentence and not necessarily at the start of sentence. Example: {"ou" ,"suyoypayul" ,"eim","otehzri"} "otehzriabeimabouabsuyoypayulabouab" In the above case, the above-discussed algorithm will not return all words present in the sentence (that are present in the dictionary).
@RahulMaurya-tc2wi
@RahulMaurya-tc2wi 4 жыл бұрын
yes,this approach will fail in this type of cases! Do you have another approach?
@LegitGamer2345
@LegitGamer2345 3 жыл бұрын
maybe what u are saying can be resolved by taking subsets of the string instead of prefixes
@yatinarora1252
@yatinarora1252 3 жыл бұрын
Two pointer may help😐
@naitikverma6586
@naitikverma6586 3 жыл бұрын
gfg pe to ispe AC aya
@deepakjumani6446
@deepakjumani6446 4 жыл бұрын
sir ek hi sentence m dictionary vaale array ke 1 hi word ko do baar use ke skte h kya?
@LegitGamer2345
@LegitGamer2345 3 жыл бұрын
yes
@nidhirathore7284
@nidhirathore7284 2 жыл бұрын
Thank you Sir 😄😄😄😄
@sandeeprajurs1994
@sandeeprajurs1994 3 жыл бұрын
just wanted to know how to prepare for ds and algos interview. Is it like we need to solve questions on all topics and in interview we just need to find the question belongs to which pattern that we have already solved...based on that we need to come up with solution rite?
@LegitGamer2345
@LegitGamer2345 3 жыл бұрын
yes sir
@ankitamehra5045
@ankitamehra5045 4 жыл бұрын
sir how to prepare for online tests..do we need to do competitive for that. under time pressure approach nahi anti dimaag main in online assessment
@Pepcoding
@Pepcoding 4 жыл бұрын
beta competitive necessary nahi hai, beneficial hai. 90% of my students who did it, did without competitive.
@utkarshshrivastava3647
@utkarshshrivastava3647 3 жыл бұрын
@@Pepcoding sir maximum offcampus coding rounds ke liye competitive strong hona chahiye na?
@mickyman753
@mickyman753 3 жыл бұрын
@@utkarshshrivastava3647 nhi ,mostly 3-4 companies hi hai jinke liye jaruri ai ,baaki mai dsa se hi ho jata hai
@ravikishores
@ravikishores 3 жыл бұрын
Will it work for string=abcd and dictionary={ab, abc, d}.. Solution is picking "ab" first , then it will only search for cd..
@Pepcoding
@Pepcoding 3 жыл бұрын
Buddy, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
@nidhirathore7284
@nidhirathore7284 2 жыл бұрын
It will work fined
@rupeshsharma9235
@rupeshsharma9235 4 жыл бұрын
sir ,you are great
@Pepcoding
@Pepcoding 4 жыл бұрын
Keep learning
@rahulbhatia3075
@rahulbhatia3075 4 жыл бұрын
Superb explaination
@Pepcoding
@Pepcoding 4 жыл бұрын
Glad you liked it
@satvrii
@satvrii Жыл бұрын
@punitsharma4424
@punitsharma4424 4 жыл бұрын
sir how many question is left in backtracking?
@Pepcoding
@Pepcoding 4 жыл бұрын
total 50 hai level 2 mei, level 1 ke 30 ho chuke. level 2 ke takreeban 20 ho chuke. level 2 mei abhi 30 aur karenge. Inn 80 questions ko jisne ache se kar lia wo kam se kam recursion and backtracking mei kabhi kahin nahi fassega.
@punitsharma4424
@punitsharma4424 4 жыл бұрын
Thank you sir
@mayur_madhwani03
@mayur_madhwani03 3 жыл бұрын
code khud hi likh liya itna sahi samjhaya hai na sir jo question is topic se related nahi hai vo bhi ban jaate hai just because you teach how to think
@abheetsingh9938
@abheetsingh9938 4 жыл бұрын
the submission fails for this test case: "aaaaaaa" ["aaaa","aaa"]
@vishalm784
@vishalm784 4 жыл бұрын
It works...Please check your implementation
@siddhantkumar9492
@siddhantkumar9492 3 жыл бұрын
@@vishalm784 It's not working,can you send your code
@shauncrasta619
@shauncrasta619 3 жыл бұрын
TLE de raha he leetcode pe...
@puskinmittal8956
@puskinmittal8956 4 жыл бұрын
sir how to use DP in it?
@Pepcoding
@Pepcoding 4 жыл бұрын
Ye bhi aaega beta. DP mei aaega alag se
@tusharagarwal3475
@tusharagarwal3475 4 жыл бұрын
Isme backtracking kha use hui hai
@vikkasmaheshwari862
@vikkasmaheshwari862 2 жыл бұрын
Jo ans me left string ka addtion krke pass kr rhe hai parameter me wo ek trh ka backtrack hai kyunki function call hone ke bad ans same wohi bn jaega sirf function ki call me left string add kiya hai. Agr isko alg ds me add krke pass krte to you can see easily how backtracking happening
@bikramjitdas2621
@bikramjitdas2621 3 жыл бұрын
This code is returning me an empty string,can anyone help out? int helperdict(vector& dict, string left, int n) { for(int i = 0; i
@rohandevaki4349
@rohandevaki4349 2 жыл бұрын
we need solution which works on leetcode, not on pepcoding ,
@arpanbanejee5143
@arpanbanejee5143 3 жыл бұрын
Can anyone help me with the memoization of this code? class Solution { private List solve(String s,Set seen,String op, List res){ if(s.length()==0){ res.add(op.trim()); return res; } for(int i=1;i
@CodeCraftWithVinayak
@CodeCraftWithVinayak 4 жыл бұрын
submission me Kuch problem hai shayed, same code mene bar bar submit kiya pura test cases pass hua kabi kuch fail hua: Submission ID: 517616 (comple passed) 517614 (failed few ) same code hai likein
@ayushgoel9584
@ayushgoel9584 4 жыл бұрын
www.geeksforgeeks.org/magnet-puzzle-backtracking-9/ , sir isko bhi ek baar solvekara dijiyega , kaafi insight milegi isse, google has also asked variations of this question 3-4 times.
@Pepcoding
@Pepcoding 4 жыл бұрын
hanji, it's a favourite with us as well. Aj he daalenge.
Word Break - Dynamic Programming - Leetcode 139 - Python
15:35
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 12 МЛН
Word Break Problem | Dynamic Programming | GeeksforGeeks
19:07
GeeksforGeeks
Рет қаралды 54 М.
How to Solve Sudoku using Backtracking | Recursion
31:18
Pepcoding
Рет қаралды 84 М.
Word Break | Dynamic Programming | Leetcode #139
36:55
Techdose
Рет қаралды 94 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 743 М.
L17. Palindrome Partitioning | Leetcode | Recursion | C++ | Java
24:34
take U forward
Рет қаралды 287 М.
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН