guys who ever is confused with '^' in Stringbuilder it is to handle below kind of tree node TreeNode root = new TreeNode(12); TreeNode subRoot = new TreeNode(2); where 12 (tweleve) will be treated as 1,2 subtree as 2 it gives true to figure out item or data in node we are using ^ as seperator still if u need confirmation pls refer test case created by nikhil in description code and nikhil small suggestion pls explain or stick to same logic during dry run , this will give more clarification and reduces doubts , in last example no null were included in ur explanation rest vedio is very helpful thank you ❤
@alisheheryar17708 ай бұрын
you have to add string("^") to your initial string otherwise it breaks at special cases like s = 12nullnull t = 2nullnull Cheeky Nikhil.
@garvitarora77777 ай бұрын
thanks bro
@rahulsinghdeo7519 Жыл бұрын
Hey can you please explain how the "sb" object of String builder is preserve-ing the value when it moves to next iteration.
@syedomarali26784 ай бұрын
It won't take O(n). Java's .contains() works in O(MN). Use efficient pattern-matching algorithms like KMP to achieve linear TC.
@AlexTopGT Жыл бұрын
thank you! best explanation.
@minnikeswarrao6185 Жыл бұрын
Time complexity shouldn't be O(n) ...since String.contains() takes O(m+n)
@nikoo2805 Жыл бұрын
O(m + n) will translate to O(n), where n > m
@pranavm93019 ай бұрын
O(m+n) is still O(n) since m O(2n) which is worst case when n=m, which is still O(n)
@smridhjain41005 ай бұрын
Whenever you put StringBuilder sb = new StringBuilder("^"); it passes the test cases but if you dont put the ^ it fails a single test case of root =[1,2] and subroot=[2] , can you explain why please? I think this is the same query that others trying to ask in the comment section
@nikoo285 ай бұрын
you have to add string("^") to your initial string otherwise it breaks at special cases like s = 12nullnull t = 2nullnull
@shrirambalaji2915 Жыл бұрын
Thank you brother
@killeraloo324711 ай бұрын
OP solution. 🧡 from remote.
@djpsn7094 Жыл бұрын
Why we took ^ in StringBuilder
@nikoo28 Жыл бұрын
it is just an anchor
@suryaram687422 күн бұрын
what about inorder traversal?
@yemeniabedontaclf Жыл бұрын
Repeated DNA Sequences. make vedio about this
@Rieshu-l9i8 ай бұрын
Solve "node at distance k from target node" Please🙏
@pratyushtripathy14638 ай бұрын
Only pre-Order traversal will work here, In other 2 (POT & IOT) all TCs will not pass
@codeLine7 Жыл бұрын
very nice explanation.
@nikoo28 Жыл бұрын
Keep watching
@varundwivedi1079 Жыл бұрын
Great.Thanks
@blacklight8932 Жыл бұрын
didnt work for all testcases
@nikoo28 Жыл бұрын
Check the code in description. It passes on leetcode
@adirang3 ай бұрын
@nikoo28 The solution does not work for in order traversal when root is [1,2,3] and sub root is [1,2]. Code returns True but should be False.
@garvitarora77777 ай бұрын
this is failing in this test case sir Input root =[12] subRoot =[2]
@nikoo287 ай бұрын
What output are you expecting?
@sheikhmkrifat77497 ай бұрын
i applied the same way in inorder and postorder after that it doesn't pass all the test cases in leetcode.
@aryavardhansingh21627 ай бұрын
same here do you know the reason ?
@sheikhmkrifat77497 ай бұрын
@@aryavardhansingh2162 yeah, i found that preOrder is used for comparing structure of BT, cause here root node comes first , then left and right on the other hand inorder and post dosent follow this, for that preOrder is used to compare two BT.
@shahriarbadhon4596 Жыл бұрын
Nice
@sumeersaifi635410 ай бұрын
you code is not fully correct if there is root 12 and subroot 2 then for 12 it will be 12nullnull and for will be 2nullnull and when you check root.contain(subroot) it will give true but it should be false
@nikoo289 ай бұрын
it passes the constraints on leetcode. can you explain your test case a little better?
@sumeersaifi63549 ай бұрын
I need to check will let you know
@AniketWaghmare-qi7wm2 ай бұрын
Hey @nikoo28 Please Make Video On Question Number 110. Balanced Binary Tree. Please Make video fast because my interview in Amazon. And your teaching is so good
@BACSShaileshShettar8 ай бұрын
test cases failing
@nikoo288 ай бұрын
check the code in the github link provided in video description.
@adirang3 ай бұрын
@@nikoo28The solution does not work for in order traversal when root is [1,2,3] and sub root is [1,2]. Code returns True but should be False.
@nikoo283 ай бұрын
@@adirang just checked again, code is returning False.
@droid-aman7 ай бұрын
love ur explanion v much,, +1 suscription from my side buddy!!
@thor16268 ай бұрын
will fail only one test case. Anyways this method is not recommended, good explanation tho.